kitchensync

pluginpicker.cpp
1/*
2 This file is part of KitchenSync.
3
4 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 USA.
20*/
21
22#include "pluginpicker.h"
23
24#include "memberinfo.h"
25#include "syncprocessmanager.h"
26
27#include <libqopensync/environment.h>
28
29#include <kdialog.h>
30#include <tdeglobal.h>
31#include <kiconloader.h>
32#include <tdelocale.h>
33
34#include <tqlabel.h>
35#include <tqlayout.h>
36
37PluginItem::PluginItem( KWidgetList *list, const QSync::Plugin &plugin )
38 : KWidgetListItem( list ), mPlugin( plugin )
39{
40 TQString iconName = MemberInfo::pluginIconName( mPlugin.name() );
41 TQGridLayout *layout = new TQGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
42
43 TQLabel *icon = new TQLabel( this );
44 icon->setPixmap( TDEGlobal::iconLoader()->loadIcon( iconName, TDEIcon::Desktop ) );
45 icon->setFixedSize( icon->sizeHint() );
46
47 TQLabel *name = new TQLabel( plugin.longName(), this );
48 TQLabel *description = new TQLabel( plugin.description(), this );
49
50 TQFont font = name->font();
51 font.setBold( true );
52 name->setFont( font );
53
54 layout->addWidget( icon, 0, 0 );
55 layout->addWidget( name, 0, 1 );
56 layout->addWidget( description, 1, 1 );
57}
58
59
60PluginPicker::PluginPicker( TQWidget *parent )
61 : TQWidget( parent )
62{
63 TQBoxLayout *layout = new TQVBoxLayout( this );
64
65 mPluginList = new KWidgetList( this );
66 layout->addWidget( mPluginList );
67
68 connect( mPluginList, TQT_SIGNAL( doubleClicked( KWidgetListItem* ) ),
69 TQT_SIGNAL( selected() ) );
70
71 updatePluginList();
72
73 mPluginList->setFocus();
74}
75
76void PluginPicker::updatePluginList()
77{
78 mPluginList->clear();
79
80 QSync::Environment *env = SyncProcessManager::self()->environment();
81
82 QSync::Environment::PluginIterator it( env->pluginBegin() );
83 for( ; it != env->pluginEnd(); ++it ) {
84 QSync::Plugin plugin = *it;
85 mPluginList->appendItem( new PluginItem( mPluginList, plugin ) );
86 }
87}
88
89QSync::Plugin PluginPicker::selectedPlugin() const
90{
91 PluginItem *item = static_cast<PluginItem *>( mPluginList->selectedItem() );
92 if ( item ) return item->plugin();
93 else return QSync::Plugin();
94}
95
96
97PluginPickerDialog::PluginPickerDialog( TQWidget *parent )
98 : KDialogBase( parent, 0, true, i18n("Select Member Type"), Ok | Cancel )
99{
100 TQFrame *topFrame = makeMainWidget();
101
102 TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
103
104 mPicker = new PluginPicker( topFrame );
105 topLayout->addWidget( mPicker );
106
107 connect( mPicker, TQT_SIGNAL( selected() ), TQT_SLOT( slotOk() ) );
108
109 setInitialSize( TQSize( 460, 380 ) );
110}
111
112QSync::Plugin PluginPickerDialog::selectedPlugin() const
113{
114 return mPicker->selectedPlugin();
115}
116
117QSync::Plugin PluginPickerDialog::getPlugin( TQWidget *parent )
118{
119 PluginPickerDialog dlg( parent );
120 if ( dlg.exec() )
121 return dlg.selectedPlugin();
122 else
123 return QSync::Plugin();
124}
125
126void PluginPickerDialog::slotOk()
127{
128 accept();
129}
130
131void PluginPickerDialog::slotCancel()
132{
133 reject();
134}
135
136#include "pluginpicker.moc"