author | zecke <zecke> | 2004-09-12 23:56:54 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-12 23:56:54 (UTC) |
commit | 848be27ce441430b6946221cd288ff9d6297096c (patch) (side-by-side diff) | |
tree | 1ff3d0bad98bee9d5dd0ff70f3eedd5484e25ab6 | |
parent | df292cd5dbd8f3c11efa06db1a2ed565a6efa9b8 (diff) | |
download | opie-848be27ce441430b6946221cd288ff9d6297096c.zip opie-848be27ce441430b6946221cd288ff9d6297096c.tar.gz opie-848be27ce441430b6946221cd288ff9d6297096c.tar.bz2 |
-Refactor loading of the Plugin Widgets' to be only contained
in one place.
-Reload the Plugins after configuration to reflect the changes
immediately
-rw-r--r-- | core/pim/today/plugins/datebook/datebookplugin.cpp | 2 | ||||
-rw-r--r-- | core/pim/today/plugins/todolist/todoplugin.cpp | 2 | ||||
-rw-r--r-- | core/pim/today/today.cpp | 172 | ||||
-rw-r--r-- | core/pim/today/today.h | 8 | ||||
-rw-r--r-- | core/pim/today/todayconfig.cpp | 7 |
5 files changed, 76 insertions, 115 deletions
diff --git a/core/pim/today/plugins/datebook/datebookplugin.cpp b/core/pim/today/plugins/datebook/datebookplugin.cpp index 892a0ad..bef284e 100644 --- a/core/pim/today/plugins/datebook/datebookplugin.cpp +++ b/core/pim/today/plugins/datebook/datebookplugin.cpp @@ -25,47 +25,47 @@ DatebookPlugin::~DatebookPlugin() { } QString DatebookPlugin::pluginName() const { return QObject::tr( "Datebook plugin"); } double DatebookPlugin::versionNumber() const { return 1.0; } QString DatebookPlugin::pixmapNameWidget() const { return "datebook/DateBook"; } QWidget* DatebookPlugin::widget( QWidget* wid ) { m_widget = new DatebookPluginWidget( wid, "Datebook" ); return m_widget; } QString DatebookPlugin::pixmapNameConfig() const { return "datebook/DateBook"; } TodayConfigWidget* DatebookPlugin::configWidget( QWidget* wid ) { - return new DatebookPluginConfig( wid , "Datebook" ); + return new DatebookPluginConfig( wid , "Datebook Config" ); } QString DatebookPlugin::appName() const { return "datebook"; } bool DatebookPlugin::excludeFromRefresh() const { return false; } void DatebookPlugin::refresh() { if ( m_widget ) { m_widget->refresh(); } } void DatebookPlugin::reinitialize() { if ( m_widget ) { m_widget->reinitialize(); } } diff --git a/core/pim/today/plugins/todolist/todoplugin.cpp b/core/pim/today/plugins/todolist/todoplugin.cpp index 6cfcbe0..4be5673 100644 --- a/core/pim/today/plugins/todolist/todoplugin.cpp +++ b/core/pim/today/plugins/todolist/todoplugin.cpp @@ -26,47 +26,47 @@ TodolistPlugin::~TodolistPlugin() { } QString TodolistPlugin::pluginName() const { return QObject::tr( "Todolist plugin" ); } double TodolistPlugin::versionNumber() const { return 0.9; } QString TodolistPlugin::pixmapNameWidget() const { return "todo/TodoList"; } QWidget* TodolistPlugin::widget( QWidget *wid ) { m_widget = new TodolistPluginWidget( wid, "Todolist" ); return m_widget; } QString TodolistPlugin::pixmapNameConfig() const { return "todo/TodoList"; } TodayConfigWidget* TodolistPlugin::configWidget( QWidget* wid ) { - return new TodolistPluginConfig( wid , "Todolist" ); + return new TodolistPluginConfig( wid , "Todolist Config" ); } QString TodolistPlugin::appName() const { return "todolist"; } bool TodolistPlugin::excludeFromRefresh() const { return false; } void TodolistPlugin::refresh() { if ( m_widget ) { m_widget->refresh(); } } void TodolistPlugin::reinitialize() { if ( m_widget ) { m_widget->reinitialize(); } } diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index be7cbce..3e895a4 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp @@ -29,81 +29,87 @@ #include <qtimer.h> #include <qwhatsthis.h> #include <qmessagebox.h> using namespace Opie::Ui; using Opie::Core::OPluginItem; using Opie::Core::OPluginLoader; using Opie::Core::OPluginManager; using Opie::Core::OConfig; struct TodayPlugin { TodayPlugin() : iface( 0 ), guiPart( 0 ), guiBox( 0 ) {} QInterfacePtr<TodayPluginInterface> iface; TodayPluginObject *guiPart; OPluginItem oplugin; QWidget *guiBox; QString name; bool excludeRefresh; }; static QMap<QString, TodayPlugin> pluginList; Today::Today( QWidget* parent, const char* name, WFlags fl ) -: TodayBase( parent, name, fl ) { +: TodayBase( parent, name, fl | WStyle_ContextHelp) { - QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); - QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); + setCaption( tr("Today") ); + connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); + connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); #if !defined(QT_NO_COP) QCopChannel *todayChannel = new QCopChannel( "QPE/Today" , this ); connect ( todayChannel, SIGNAL( received(const QCString&,const QByteArray&) ), this, SLOT ( channelReceived(const QCString&,const QByteArray&) ) ); #endif setOwnerField(); - m_big_box = 0L; + m_big_box = 0l; + m_bblayout = 0l; layout = new QVBoxLayout( this ); layout->addWidget( Frame ); layout->addWidget( OwnerField ); + + m_informationLabel = new QLabel( tr("No plugins activated"), this ); + layout->addWidget( m_informationLabel ); + m_sv = new QScrollView( this ); m_sv->setResizePolicy( QScrollView::AutoOneFit ); m_sv->setHScrollBarMode( QScrollView::AlwaysOff ); m_sv->setFrameShape( QFrame::NoFrame ); layout->addWidget( m_sv ); layout->setStretchFactor( m_sv,4 ); m_refreshTimer = new QTimer( this ); connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); - init(); loadPlugins(); - initialize(); + loadShellContent(); + loadPluginWidgets(); } /** * Qcop receive method. */ void Today::channelReceived( const QCString &msg, const QByteArray & data ) { QDataStream stream( data, IO_ReadOnly ); if ( msg == "message(QString)" ) { QString message; stream >> message; setOwnerField( message ); } } void Today::setRefreshTimer( int interval ) { disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); // 0 is "never" case if ( !interval == 0 ) { connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); m_refreshTimer->changeInterval( interval ); } } @@ -112,253 +118,199 @@ void Today::setRefreshTimer( int interval ) { * Initialises the owner field with the default value, the username */ void Today::setOwnerField() { QString file = Global::applicationFileName( "addressbook", "businesscard.vcf" ); if ( QFile::exists( file ) ) { Contact cont = Contact::readVCard( file )[0]; QString returnString = cont.fullName(); OwnerField->setText( "<b>" + tr ( "Owned by " ) + returnString + "</b>" ); } else { OwnerField->setText( "<b>" + tr ( "Please fill out the business card" ) + " </b>" ); } } /** * Set the owner field with a given QString, for example per qcop. */ void Today::setOwnerField( QString &message ) { if ( !message.isEmpty() ) { OwnerField->setText( "<b>" + message + "</b>" ); } } /** - * Init stuff needed for today. Reads the config file. + * Load the plugins */ -void Today::init() { - // read config - OConfig cfg( "today" ); +void Today::loadPlugins() { + m_pluginLoader = new OPluginLoader( "today", true ); + m_pluginLoader->setAutoDelete( true ); + + m_manager = new OPluginManager( m_pluginLoader ); + m_manager->load(); +} + +void Today::loadShellContent() { + Config cfg( "today" ); cfg.setGroup( "Plugins" ); - // m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); - // m_allApplets = cfg.readListEntry( "AllApplets", ',' ); + cfg.setGroup( "General" ); m_iconSize = cfg.readNumEntry( "IconSize", 18 ); m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); // set the date in top label QDate date = QDate::currentDate(); DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( date ) + "</font>" ) ); if ( m_hideBanner ) { Opiezilla->hide(); TodayLabel->hide(); } else { Opiezilla->show(); TodayLabel->show(); } - - if ( m_big_box ) { - delete m_big_box; - } - - m_big_box = new QWidget( m_sv->viewport() ); - m_sv->addChild( m_big_box ); - m_bblayout = new QVBoxLayout ( m_big_box ); } - -/** - * Load the plugins - */ -void Today::loadPlugins() { - - m_pluginLoader = new OPluginLoader( "today", true ); - m_pluginLoader->setAutoDelete( true ); - - m_manager = new OPluginManager( m_pluginLoader ); - m_manager->load(); - +void Today::loadPluginWidgets() { /* * check if loading of Plugins crashed */ if( m_pluginLoader->isInSafeMode() ) { QMessageBox::information(this, tr("Today Error"), tr("<qt>The plugin '%1' caused Today to crash." " It could be that the plugin is not properly" " installed.<br>Today tries to continue loading" " plugins.</qt>") .arg( m_manager->crashedPlugin().name())); } OPluginItem::List lst = m_pluginLoader->filtered( true ); + /* + * Show or Hide the information of no plugin installed + */ + if ( lst.isEmpty() ) + m_informationLabel->show(); + else + m_informationLabel->hide(); + + + /* + * Now let us add the plugins + */ + m_big_box = new QWidget( m_sv->viewport() ); + m_sv->addChild( m_big_box ); + m_bblayout = new QVBoxLayout( m_big_box ); for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); TodayPlugin plugin; plugin.iface = iface; plugin.name = (*it).name(); plugin.oplugin = (*it); plugin.guiPart = plugin.iface->guiPart(); plugin.excludeRefresh = plugin.guiPart->excludeFromRefresh(); // package the whole thing into a qwidget so it can be shown and hidden plugin.guiBox = new QWidget( m_big_box ); QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); QPixmap plugPix; plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( m_iconSize, m_iconSize ), 0 ); OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); plugIcon->setPixmap( plugPix ); QWhatsThis::add ( plugIcon, tr("Click here to launch the associated app") ); plugIcon->setName( plugin.guiPart->appName() ); connect( plugIcon, SIGNAL( clicked() ), this, SLOT( startApplication() ) ); QWidget *plugWidget = plugin.guiPart->widget( plugin.guiBox ); boxLayout->addWidget( plugIcon, 0, AlignTop ); boxLayout->addWidget( plugWidget, 0, AlignTop ); boxLayout->setStretchFactor( plugIcon, 1 ); boxLayout->setStretchFactor( plugWidget, 9 ); pluginList.insert( plugin.name, plugin ); m_bblayout->addWidget(plugin.guiBox); } m_bblayout->addStretch( 1 ); + m_big_box->show(); } /** * The method for the configuration dialog. */ void Today::startConfig() { - // disconnect timer to prevent problems while being on config dialog disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); m_refreshTimer->stop( ); TodayConfig conf( this, "dialog", true ); conf.setUpPlugins( m_manager, m_pluginLoader ); if ( QPEApplication::execDialog(&conf) == QDialog::Accepted ) { conf.writeConfig(); - initialize(); + clearPluginWidgets(); + loadShellContent(); + loadPluginWidgets(); } else { // since reinitialize is not called in that case , reconnect the signal m_refreshTimer->start( 15000 ); // get the config value in here later connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); } } - -void Today::initialize() { - - Config cfg( "today" ); - cfg.setGroup( "Plugins" ); - - - cfg.setGroup( "General" ); - m_iconSize = cfg.readNumEntry( "IconSize", 18 ); - m_hideBanner = cfg.readNumEntry( "HideBanner", 0 ); - setRefreshTimer( cfg.readNumEntry( "checkinterval", 15000 ) ); - - // set the date in top label - QDate date = QDate::currentDate(); - DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( date ) + "</font>" ) ); - - if ( m_hideBanner ) { - Opiezilla->hide(); - TodayLabel->hide(); - } else { - Opiezilla->show(); - TodayLabel->show(); - } - - if ( m_bblayout ) { - delete m_bblayout; - } - m_bblayout = new QVBoxLayout ( m_big_box ); - - if ( pluginList.count() == 0 ) { - QLabel *noPlugins = new QLabel( this ); - noPlugins->setText( tr( "No plugins found" ) ); - layout->addWidget( noPlugins ); - } else { - - uint count = 0; - TodayPlugin tempPlugin; - OPluginItem::List lst = m_pluginLoader->allAvailable( true ); - for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { - - TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); - - tempPlugin = ( pluginList.find( (*it).name() ).data() ); - if ( !( (tempPlugin.name).isEmpty() ) ) { - if ( (*it).isEnabled() ) { - iface->guiPart()->reinitialize(); - odebug << "reinit" << oendl; - tempPlugin.guiBox->show(); - m_bblayout->addWidget(tempPlugin.guiBox); - count++; - } else { - tempPlugin.guiBox->hide(); - } - } - } - if ( count == 0 ) { - QLabel *noPluginsActive = new QLabel( this ); - noPluginsActive->setText( tr( "No plugins activated" ) ); - layout->addWidget( noPluginsActive ); - } - } - m_bblayout->addStretch( 1 ); - repaint(); -} - /** * Refresh for the view. Reload all applets * */ void Today::refresh() { - - OPluginItem::List lst = m_pluginLoader->filtered( true ); - - for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { - TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); - iface->guiPart()->refresh(); - odebug << "refresh" << oendl; - } + for ( QMap<QString, TodayPlugin>::Iterator it = pluginList.begin(); + it != pluginList.end(); ++it ) + it.data().guiPart->refresh(); DateLabel->setText( QString( "<font color=#FFFFFF>" + TimeString::longDateString( QDate::currentDate() ) + "</font>" ) ); updateGeometry(); repaint(); } void Today::startApplication() { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( sender()->name() ); } /** * launch addressbook (personal card) */ void Today::editCard() { QCopEnvelope env( "QPE/Application/addressbook", "editPersonalAndClose()" ); } Today::~Today() { - for(QMap<QString, TodayPlugin>::Iterator it = pluginList.begin(); it != pluginList.end(); ++it ) - delete it.data().guiBox; - + clearPluginWidgets(); delete m_pluginLoader; delete m_manager; } + +void Today::clearPluginWidgets() { + for(QMap<QString, TodayPlugin>::Iterator it = pluginList.begin(); it != pluginList.end(); ++it ) { + delete it.data().guiBox; + it.data().guiBox = 0; + } + + pluginList.clear(); + + delete m_bblayout; + delete m_big_box; + m_bblayout = 0; + m_big_box = 0; +} diff --git a/core/pim/today/today.h b/core/pim/today/today.h index dfc819d..8dbe9aa 100644 --- a/core/pim/today/today.h +++ b/core/pim/today/today.h @@ -35,56 +35,60 @@ class QVBoxLayout; namespace Opie { namespace Core { class OPluginManager; class OPluginLoader; } } class Today : public TodayBase { Q_OBJECT public: Today( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~Today(); static QString appName() { return QString::fromLatin1("today"); } private slots: void startConfig(); void startApplication(); void editCard(); void refresh(); private: - void init(); void setOwnerField(); void setOwnerField(QString &string); - void initialize(); void setRefreshTimer( int ); + void clearPluginWidgets(); + void loadPluginWidgets(); + void loadShellContent(); + + private slots: void channelReceived(const QCString &msg, const QByteArray & data); void loadPlugins(); private: TodayConfig *conf; QStringList m_excludeApplets; QStringList m_allApplets; QScrollView *m_sv; QWidget* m_big_box; QVBoxLayout *m_bblayout; + QLabel *m_informationLabel; Opie::Core::OPluginLoader *m_pluginLoader; Opie::Core::OPluginManager *m_manager; QTimer *m_refreshTimer; bool m_refreshTimerEnabled; int m_newStart; int m_iconSize; int m_maxCharClip; int m_hideBanner; }; #endif diff --git a/core/pim/today/todayconfig.cpp b/core/pim/today/todayconfig.cpp index dacce8b..864c708 100644 --- a/core/pim/today/todayconfig.cpp +++ b/core/pim/today/todayconfig.cpp @@ -72,49 +72,48 @@ TodayConfig::TodayConfig( QWidget* parent, const char* name, bool modal ) QLabel *l = new QLabel( tr( "Load which plugins in what order:" ), tab_2 ); tab2Layout->addWidget( l ); QHBox *hbox1 = new QHBox( tab_2 ); m_appletListView = new QListView( hbox1 ); m_appletListView->addColumn( "PluginList" ); m_appletListView->header()->hide(); m_appletListView->setSorting( -1 ); QWhatsThis::add ( m_appletListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the appearance order" ) ); QVBox *vbox1 = new QVBox( hbox1 ); new ToolButton( vbox1, tr( "Move Up" ), "up", this , SLOT( moveSelectedUp() ) ); new ToolButton( vbox1, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) ); tab2Layout->addWidget( hbox1 ); TabWidget3->addTab( tab_2, "pass", tr( "active/order" ) ); // Misc tab tab_3 = new QWidget( TabWidget3, "tab_3" ); QVBoxLayout *tab3Layout = new QVBoxLayout( tab_3 ); m_guiMisc = new TodayConfigMiscBase( tab_3 ); tab3Layout->addWidget( m_guiMisc ); TabWidget3->addTab( tab_3, "SettingsIcon", tr( "Misc" ) ); - connect ( m_appletListView , SIGNAL( clicked(QListViewItem*) ), this, SLOT( appletChanged() ) ); previousItem = 0l; readConfig(); } void TodayConfig::setUpPlugins( OPluginManager * plugManager, OPluginLoader *plugLoader ) { m_configMap.clear(); m_pluginManager = plugManager; m_pluginLoader = plugLoader; OPluginItem::List inLst = m_pluginLoader->allAvailable( true ); OPluginItem::List lst; for ( OPluginItem::List::Iterator it = inLst.begin(); it != inLst.end(); ++it ) { lst.prepend((*it)); TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); TodayConfigWidget *widget = iface->guiPart()->configWidget( TabWidget3 ); if (!widget ) continue; m_configMap.insert( iface, widget ); @@ -160,76 +159,82 @@ void TodayConfig::readConfig() { m_guiMisc->SpinBoxTime->setValue( m_autoStartTimer ); cfg.setGroup( "General" ); m_iconSize = cfg.readNumEntry( "IconSize", 18 ); m_guiMisc->SpinBoxIconSize->setValue( m_iconSize ); m_guiMisc->SpinRefresh->setValue( cfg.readNumEntry( "checkinterval", 15000 ) / 1000 ); m_guiMisc->CheckBoxHide->setChecked( cfg.readNumEntry( "HideBanner", 0 ) ); } /** * Write the config part */ void TodayConfig::writeConfig() { OConfig cfg( "today" ); int position = m_appletListView->childCount(); QListViewItemIterator list_it( m_appletListView ); OPluginItem::List lst = m_pluginLoader->allAvailable( true ); // this makes sure the names get saved in the order selected for ( ; list_it.current(); ++list_it ) { for ( OPluginItem::List::Iterator it = lst.begin(); it != lst.end(); ++it ) { if ( QString::compare( (*it).name() , list_it.current()->text(0) ) == 0 ) { + qWarning( "Enabling %d and make it %d", position-1, + ((QCheckListItem*)list_it.current())->isOn() ); (*it).setPosition(position--); m_pluginManager->setEnabled( (*it),((QCheckListItem*)list_it.current())->isOn() ); } } } + /* + * save and get the changes back + */ m_pluginManager->save(); cfg.setGroup( "Autostart" ); m_autoStart = m_guiMisc->CheckBoxAuto->isChecked(); cfg.writeEntry( "autostart", m_autoStart ); m_autoStartTimer = m_guiMisc->SpinBoxTime->value(); cfg.writeEntry( "autostartdelay", m_autoStartTimer ); m_iconSize = m_guiMisc->SpinBoxIconSize->value(); cfg.setGroup( "General" ); cfg.writeEntry( "IconSize", m_iconSize ); cfg.writeEntry( "HideBanner", m_guiMisc->CheckBoxHide->isChecked() ); cfg.writeEntry( "checkinterval", m_guiMisc->SpinRefresh->value()*1000 ); // set autostart settings setAutoStart(); OPluginItem::List managedLst = m_pluginManager->managedPlugins(); for ( OPluginItem::List::Iterator it = managedLst.begin(); it != managedLst.end(); ++it ) { TodayPluginInterface* iface = m_pluginLoader->load<TodayPluginInterface>( *it, IID_TodayPluginInterface ); if ( m_configMap.contains( iface ) ) m_configMap[iface]->writeConfig(); + } } void TodayConfig::moveSelectedUp() { QListViewItem *item = m_appletListView->selectedItem(); if ( item && item->itemAbove() ) { item->itemAbove()->moveItem( item ); } } void TodayConfig::moveSelectedDown() { QListViewItem *item = m_appletListView->selectedItem(); if ( item && item->itemBelow() ) { item->moveItem( item->itemBelow() ); } } /** * Set up the icons in the order/active tab */ void TodayConfig::pluginManagement( OPluginItem plugItem ) { |