kitchensync
pluginpicker.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "pluginpicker.h"
00023
00024 #include "memberinfo.h"
00025 #include "syncprocessmanager.h"
00026
00027 #include <libqopensync/environment.h>
00028
00029 #include <kdialog.h>
00030 #include <tdeglobal.h>
00031 #include <kiconloader.h>
00032 #include <tdelocale.h>
00033
00034 #include <tqlabel.h>
00035 #include <tqlayout.h>
00036
00037 PluginItem::PluginItem( KWidgetList *list, const QSync::Plugin &plugin )
00038 : KWidgetListItem( list ), mPlugin( plugin )
00039 {
00040 TQString iconName = MemberInfo::pluginIconName( mPlugin.name() );
00041 TQGridLayout *layout = new TQGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
00042
00043 TQLabel *icon = new TQLabel( this );
00044 icon->setPixmap( TDEGlobal::iconLoader()->loadIcon( iconName, TDEIcon::Desktop ) );
00045 icon->setFixedSize( icon->sizeHint() );
00046
00047 TQLabel *name = new TQLabel( plugin.longName(), this );
00048 TQLabel *description = new TQLabel( plugin.description(), this );
00049
00050 TQFont font = name->font();
00051 font.setBold( true );
00052 name->setFont( font );
00053
00054 layout->addWidget( icon, 0, 0 );
00055 layout->addWidget( name, 0, 1 );
00056 layout->addWidget( description, 1, 1 );
00057 }
00058
00059
00060 PluginPicker::PluginPicker( TQWidget *parent )
00061 : TQWidget( parent )
00062 {
00063 TQBoxLayout *layout = new TQVBoxLayout( this );
00064
00065 mPluginList = new KWidgetList( this );
00066 layout->addWidget( mPluginList );
00067
00068 connect( mPluginList, TQT_SIGNAL( doubleClicked( KWidgetListItem* ) ),
00069 TQT_SIGNAL( selected() ) );
00070
00071 updatePluginList();
00072
00073 mPluginList->setFocus();
00074 }
00075
00076 void PluginPicker::updatePluginList()
00077 {
00078 mPluginList->clear();
00079
00080 QSync::Environment *env = SyncProcessManager::self()->environment();
00081
00082 QSync::Environment::PluginIterator it( env->pluginBegin() );
00083 for( ; it != env->pluginEnd(); ++it ) {
00084 QSync::Plugin plugin = *it;
00085 mPluginList->appendItem( new PluginItem( mPluginList, plugin ) );
00086 }
00087 }
00088
00089 QSync::Plugin PluginPicker::selectedPlugin() const
00090 {
00091 PluginItem *item = static_cast<PluginItem *>( mPluginList->selectedItem() );
00092 if ( item ) return item->plugin();
00093 else return QSync::Plugin();
00094 }
00095
00096
00097 PluginPickerDialog::PluginPickerDialog( TQWidget *parent )
00098 : KDialogBase( parent, 0, true, i18n("Select Member Type"), Ok | Cancel )
00099 {
00100 TQFrame *topFrame = makeMainWidget();
00101
00102 TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
00103
00104 mPicker = new PluginPicker( topFrame );
00105 topLayout->addWidget( mPicker );
00106
00107 connect( mPicker, TQT_SIGNAL( selected() ), TQT_SLOT( slotOk() ) );
00108
00109 setInitialSize( TQSize( 460, 380 ) );
00110 }
00111
00112 QSync::Plugin PluginPickerDialog::selectedPlugin() const
00113 {
00114 return mPicker->selectedPlugin();
00115 }
00116
00117 QSync::Plugin PluginPickerDialog::getPlugin( TQWidget *parent )
00118 {
00119 PluginPickerDialog dlg( parent );
00120 if ( dlg.exec() )
00121 return dlg.selectedPlugin();
00122 else
00123 return QSync::Plugin();
00124 }
00125
00126 void PluginPickerDialog::slotOk()
00127 {
00128 accept();
00129 }
00130
00131 void PluginPickerDialog::slotCancel()
00132 {
00133 reject();
00134 }
00135
00136 #include "pluginpicker.moc"
|