00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "todayconfig.h"
00032
00033 #include <opie2/oconfig.h>
00034 #include <opie2/opluginloader.h>
00035 #include <opie2/oresource.h>
00036 #include <opie2/todayplugininterface.h>
00037
00038 #include <qpe/qcopenvelope_qws.h>
00039 #include <qpe/qpeapplication.h>
00040
00041 #include <qcheckbox.h>
00042 #include <qlabel.h>
00043 #include <qspinbox.h>
00044 #include <qlayout.h>
00045 #include <qheader.h>
00046 #include <qvbox.h>
00047 #include <qtoolbutton.h>
00048 #include <qwhatsthis.h>
00049
00050 using namespace Opie::Ui;
00051 using Opie::Core::OConfig;
00052 using Opie::Core::OPluginManager;
00053 using Opie::Core::OPluginLoader;
00054 using Opie::Core::OPluginItem;
00055
00056 class ToolButton : public QToolButton {
00057
00058 public:
00059 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
00060 : QToolButton( parent, name ) {
00061 setUsesBigPixmap( true );
00062 setPixmap( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) );
00063 setAutoRaise( TRUE );
00064 setFocusPolicy( QWidget::NoFocus );
00065 setToggleButton( t );
00066 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
00067 }
00068 };
00069
00070
00076 TodayConfig::TodayConfig( QWidget* parent, const char* name, bool modal )
00077 : QDialog( parent, name, modal, WStyle_ContextHelp ) {
00078
00079 setCaption( tr( "Today Config" ) );
00080
00081 QVBoxLayout *layout = new QVBoxLayout( this );
00082 TabWidget3 = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom );
00083 layout->addWidget( TabWidget3 );
00084
00085 tab_2 = new QWidget( TabWidget3, "tab_2" );
00086 QVBoxLayout *tab2Layout = new QVBoxLayout( tab_2, 4 ,4 );
00087 QLabel *l = new QLabel( tr( "Load which plugins in what order:" ), tab_2 );
00088 tab2Layout->addWidget( l );
00089 QHBox *hbox1 = new QHBox( tab_2 );
00090 m_appletListView = new QListView( hbox1 );
00091 m_appletListView->addColumn( "PluginList" );
00092 m_appletListView->header()->hide();
00093 m_appletListView->setSorting( -1 );
00094 QWhatsThis::add
00095 ( m_appletListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the appearance order" ) );
00096 QVBox *vbox1 = new QVBox( hbox1 );
00097 new ToolButton( vbox1, tr( "Move Up" ), "up", this , SLOT( moveSelectedUp() ) );
00098 new ToolButton( vbox1, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) );
00099 tab2Layout->addWidget( hbox1 );
00100 TabWidget3->addTab( tab_2, "pass", tr( "active/order" ) );
00101
00102
00103 tab_3 = new QWidget( TabWidget3, "tab_3" );
00104 QVBoxLayout *tab3Layout = new QVBoxLayout( tab_3 );
00105
00106 m_guiMisc = new TodayConfigMiscBase( tab_3 );
00107
00108 tab3Layout->addWidget( m_guiMisc );
00109 TabWidget3->addTab( tab_3, "SettingsIcon", tr( "Misc" ) );
00110
00111 previousItem = 0l;
00112 readConfig();
00113 }
00114
00115
00116 void TodayConfig::setUpPlugins( OPluginManager * plugManager, OPluginLoader *plugLoader ) {
00117 m_configMap.clear();
00118
00119 m_pluginManager = plugManager;
00120 m_pluginLoader = plugLoader;
00121
00122 OPluginItem::List inLst = m_pluginLoader->allAvailable( true );
00123
00124 OPluginItem::List lst;
00125 for ( OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) {
00126 lst.prepend((*it));
00127
00128 TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface );
00129 TodayConfigWidget *widget = iface->guiPart()->configWidget( TabWidget3 );
00130
00131 if (!widget )
00132 continue;
00133
00134 m_configMap.insert( iface, widget );
00135 TabWidget3->addTab( widget, iface->guiPart()->pixmapNameConfig()
00136 , iface->guiPart()->appName() );
00137 }
00138
00139 for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it )
00140 pluginManagement( (*it) );
00141
00142
00143 TabWidget3->setCurrentTab( tab_2 );
00144 }
00145
00150 void TodayConfig::setAutoStart() {
00151 OConfig cfg( "today" );
00152 cfg.setGroup( "Autostart" );
00153 if ( m_autoStart ) {
00154 QCopEnvelope e( "QPE/System", "autoStart(QString,QString,QString)" );
00155 e << QString( "add" );
00156 e << QString( "today" );
00157 e << QString( "%1" ).arg( m_autoStartTimer );
00158 } else {
00159 QCopEnvelope e( "QPE/System", "autoStart(QString,QString)" );
00160 e << QString( "remove" );
00161 e << QString( "today" );
00162 }
00163 }
00164
00168 void TodayConfig::readConfig() {
00169 OConfig cfg( "today" );
00170 cfg.setGroup( "Autostart" );
00171 m_autoStart = cfg.readNumEntry( "autostart", 1 );
00172 m_guiMisc->CheckBoxAuto->setChecked( m_autoStart );
00173 m_autoStartTimer = cfg.readNumEntry( "autostartdelay", 0 );
00174 m_guiMisc->SpinBoxTime->setValue( m_autoStartTimer );
00175
00176 cfg.setGroup( "General" );
00177 m_iconSize = cfg.readNumEntry( "IconSize", 18 );
00178 m_guiMisc->SpinBoxIconSize->setValue( m_iconSize );
00179 m_guiMisc->SpinRefresh->setValue( cfg.readNumEntry( "checkinterval", 15000 ) / 1000 );
00180 m_guiMisc->CheckBoxHide->setChecked( cfg.readNumEntry( "HideBanner", 0 ) );
00181 }
00182
00186 void TodayConfig::writeConfig() {
00187 OConfig cfg( "today" );
00188
00189 int position = m_appletListView->childCount();
00190
00191 QListViewItemIterator list_it( m_appletListView );
00192 OPluginItem::List lst = m_pluginLoader->allAvailable( true );
00193
00194
00195 for ( ; list_it.current(); ++list_it ) {
00196 for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) {
00197 if ( QString::compare( (*it).name() , list_it.current()->text(0) ) == 0 ) {
00198 qWarning( "Enabling %d and make it %d", position-1,
00199 ((QCheckListItem*)list_it.current())->isOn() );
00200 (*it).setPosition(position--);
00201 m_pluginManager->setEnabled( (*it),((QCheckListItem*)list_it.current())->isOn() );
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209 m_pluginManager->save();
00210
00211 cfg.setGroup( "Autostart" );
00212 m_autoStart = m_guiMisc->CheckBoxAuto->isChecked();
00213 cfg.writeEntry( "autostart", m_autoStart );
00214 m_autoStartTimer = m_guiMisc->SpinBoxTime->value();
00215 cfg.writeEntry( "autostartdelay", m_autoStartTimer );
00216 m_iconSize = m_guiMisc->SpinBoxIconSize->value();
00217
00218 cfg.setGroup( "General" );
00219 cfg.writeEntry( "IconSize", m_iconSize );
00220 cfg.writeEntry( "HideBanner", m_guiMisc->CheckBoxHide->isChecked() );
00221 cfg.writeEntry( "checkinterval", m_guiMisc->SpinRefresh->value()*1000 );
00222
00223
00224 setAutoStart();
00225
00226 OPluginItem::List managedLst = m_pluginManager->managedPlugins();
00227 for ( OPluginItem::List::Iterator it = managedLst.begin(); it != managedLst.end(); ++it ) {
00228 TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface );
00229 if ( m_configMap.contains( iface ) )
00230 m_configMap[iface]->writeConfig();
00231
00232 }
00233 }
00234
00235
00236 void TodayConfig::moveSelectedUp() {
00237 QListViewItem *item = m_appletListView->selectedItem();
00238 if ( item && item->itemAbove() ) {
00239 item->itemAbove()->moveItem( item );
00240 }
00241 }
00242
00243
00244 void TodayConfig::moveSelectedDown() {
00245 QListViewItem *item = m_appletListView->selectedItem();
00246 if ( item && item->itemBelow() ) {
00247 item->moveItem( item->itemBelow() );
00248 }
00249 }
00250
00251
00255 void TodayConfig::pluginManagement( OPluginItem plugItem ) {
00256
00257 QCheckListItem *item = new QCheckListItem( m_appletListView, plugItem.name(), QCheckListItem::CheckBox );
00258
00259 TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( plugItem, IID_TodayPluginInterface );
00260 QPixmap icon = Opie::Core::OResource::loadPixmap( iface->guiPart()->pixmapNameWidget(), Opie::Core::OResource::SmallIcon );
00261 if ( !icon.isNull() ) {
00262 item->setPixmap( 0, icon );
00263 }
00264 item->setOn( plugItem.isEnabled() );
00265 previousItem = item;
00266 }
00267
00268
00269
00270 TodayConfig::~TodayConfig() {}