-rw-r--r-- | core/pim/today/today.cpp | 172 |
1 files changed, 62 insertions, 110 deletions
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 @@ -51,8 +51,9 @@ 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) @@ -64,5 +65,6 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) setOwnerField(); - m_big_box = 0L; + m_big_box = 0l; + m_bblayout = 0l; layout = new QVBoxLayout( this ); @@ -70,4 +72,8 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) 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 ); @@ -81,7 +87,7 @@ Today::Today( QWidget* parent, const char* name, WFlags fl ) connect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); - init(); loadPlugins(); - initialize(); + loadShellContent(); + loadPluginWidgets(); } @@ -134,12 +140,18 @@ void Today::setOwnerField( QString &message ) { /** - * 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" ); @@ -159,26 +171,7 @@ void Today::init() { 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 @@ -195,4 +188,19 @@ void Today::loadPlugins() { 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 ) { @@ -230,4 +238,5 @@ void Today::loadPlugins() { m_bblayout->addStretch( 1 ); + m_big_box->show(); } @@ -237,5 +246,4 @@ void Today::loadPlugins() { */ void Today::startConfig() { - // disconnect timer to prevent problems while being on config dialog disconnect( m_refreshTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) ); @@ -247,5 +255,7 @@ void Today::startConfig() { if ( QPEApplication::execDialog(&conf) == QDialog::Accepted ) { conf.writeConfig(); - initialize(); + clearPluginWidgets(); + loadShellContent(); + loadPluginWidgets(); } else { // since reinitialize is not called in that case , reconnect the signal @@ -255,69 +265,4 @@ void Today::startConfig() { } - -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 @@ -325,12 +270,7 @@ void Today::initialize() { */ 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>" ) ); @@ -356,9 +296,21 @@ void Today::editCard() { 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; +} |