author | harlekin <harlekin> | 2002-09-20 20:19:14 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-09-20 20:19:14 (UTC) |
commit | d2d73b6391fbc7f743199f48387d13e887bbac1e (patch) (side-by-side diff) | |
tree | 7f289628796ee4bf0bf1f32d952b5455a42b17bd | |
parent | 681e6e75efaa5577d376d0bb191afdf323cb4e75 (diff) | |
download | opie-d2d73b6391fbc7f743199f48387d13e887bbac1e.zip opie-d2d73b6391fbc7f743199f48387d13e887bbac1e.tar.gz opie-d2d73b6391fbc7f743199f48387d13e887bbac1e.tar.bz2 |
fixed the crash when closing config dialog and also sorting of the plugins is working now
-rw-r--r-- | core/pim/today/today.cpp | 54 | ||||
-rw-r--r-- | core/pim/today/today.h | 3 | ||||
-rw-r--r-- | core/pim/today/todayconfig.cpp | 51 |
3 files changed, 66 insertions, 42 deletions
diff --git a/core/pim/today/today.cpp b/core/pim/today/today.cpp index 7537631..d8b427d 100644 --- a/core/pim/today/today.cpp +++ b/core/pim/today/today.cpp @@ -47,261 +47,279 @@ struct TodayPlugin { int pos; }; static QValueList<TodayPlugin> pluginList; Today::Today( QWidget* parent, const char* name, WFlags fl ) : TodayBase( parent, name, fl ) { QObject::connect( (QObject*)ConfigButton, SIGNAL( clicked() ), this, SLOT( startConfig() ) ); QObject::connect( (QObject*)OwnerField, SIGNAL( clicked() ), this, SLOT( editCard() ) ); #if defined(Q_WS_QWS) #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 #endif setOwnerField(); refresh(); showMaximized(); } /** * 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 ); } } /** * 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. */ void Today::init() { - - QDate date = QDate::currentDate(); - QString time = ( tr( date.toString() ) ); - - DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); - // read config Config cfg( "today" ); - cfg.setGroup( "Applets" ); + cfg.setGroup( "Plugins" ); + m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); + m_allApplets = cfg.readListEntry( "AllApplets", ',' ); } /** * Load the plugins */ void Today::loadPlugins() { QValueList<TodayPlugin>::Iterator tit; for ( tit = pluginList.begin(); tit != pluginList.end(); ++tit ) { (*tit).library->unload(); delete (*tit).library; } pluginList.clear(); - QString path = QPEApplication::qpeDir() + "/plugins/today"; QDir dir( path, "lib*.so" ); QStringList list = dir.entryList(); QStringList::Iterator it; + + QMap<QString, TodayPlugin> tempList; + for ( it = list.begin(); it != list.end(); ++it ) { TodayPluginInterface *iface = 0; QLibrary *lib = new QLibrary( path + "/" + *it ); qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); if ( lib->queryInterface( IID_TodayPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); qDebug( QString(*it) ); TodayPlugin plugin; plugin.library = lib; plugin.iface = iface; plugin.name = QString(*it); // find out if plugins should be shown if ( m_excludeApplets.grep( *it ).isEmpty() ) { plugin.active = true; } else { plugin.active = false; } plugin.guiPart = plugin.iface->guiPart(); // package the whole thing into a qwidget so it can be shown and hidden plugin.guiBox = new QWidget( this ); QHBoxLayout *boxLayout = new QHBoxLayout( plugin.guiBox ); - QPixmap plugPix; plugPix.convertFromImage( Resource::loadImage( plugin.guiPart->pixmapNameWidget() ).smoothScale( 18, 18 ), 0 ); - OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); + OClickableLabel* plugIcon = new OClickableLabel( plugin.guiBox ); plugIcon->setPixmap( plugPix ); - // a scrollview for each plugin QScrollView* sv = new QScrollView( plugin.guiBox ); QWidget *plugWidget = plugin.guiPart->widget( sv->viewport() ); sv->setMinimumHeight( plugin.guiPart->minHeight() ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setHScrollBarMode( QScrollView::AlwaysOff ); sv->setFrameShape( QFrame::NoFrame ); sv->addChild( plugWidget ); - // make sure the icon is on the top alligned boxLayout->addWidget( plugIcon, 0, AlignTop ); boxLayout->addWidget( sv, 0, AlignTop ); boxLayout->setStretchFactor( plugIcon, 1 ); boxLayout->setStretchFactor( sv, 9 ); - layout->addWidget( plugin.guiBox ); + // "prebuffer" it in one more list, to get the sorting done + tempList.insert( plugin.name, plugin ); - pluginList.append( plugin ); + // on first start the list is off course empty + if ( m_allApplets.isEmpty() ) { + layout->addWidget( plugin.guiBox ); + pluginList.append( plugin ); + } } else { qDebug( "could not recognize %s", QString( path + "/" + *it ).latin1() ); delete lib; } } + + if ( !m_allApplets.isEmpty() ) { + TodayPlugin tempPlugin; + QStringList::Iterator stringit; + for( stringit = m_allApplets.begin(); stringit != m_allApplets.end(); ++stringit ) { + tempPlugin = ( tempList.find( *stringit ) ).data(); + if ( !( (tempPlugin.name).isEmpty() ) ) { + layout->addWidget( tempPlugin.guiBox ); + pluginList.append( tempPlugin ); + } + } + } } /** * Repaint method. Reread all fields. */ void Today::draw() { if ( pluginList.count() == 0 ) { QLabel *noPlugins = new QLabel( this ); noPlugins->setText( tr( "No plugins found" ) ); layout->addWidget( noPlugins ); return; } uint count = 0; TodayPlugin plugin; for ( uint i = 0; i < pluginList.count(); i++ ) { plugin = pluginList[i]; if ( plugin.active ) { qDebug( plugin.name + " is ACTIVE " ); plugin.guiBox->show(); } else { qDebug( plugin.name + " is INACTIVE" ); plugin.guiBox->hide(); } count++; } if ( count == 0 ) { QLabel *noPluginsActive = new QLabel( this ); noPluginsActive->setText( tr( "No plugins activated" ) ); layout->addWidget( noPluginsActive ); } - //layout->addStretch(0); - //layout->addItem( new QSpacerItem( 1,1, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); + layout->addStretch(0); } /** * The method for the configuration dialog. */ void Today::startConfig() { TodayConfig conf( this, "dialog", true ); TodayPlugin plugin; QList<ConfigWidget> configWidgetList; - for ( uint i = 0; i < pluginList.count(); i++ ) { + + for ( int i = pluginList.count() - 1 ; i >= 0; i-- ) { plugin = pluginList[i]; // load the config widgets in the tabs if ( plugin.guiPart->configWidget( this ) != 0l ) { - ConfigWidget* widget = plugin.guiPart->configWidget( this ); + ConfigWidget* widget = plugin.guiPart->configWidget( conf.TabWidget3 ); configWidgetList.append( widget ); conf.TabWidget3->insertTab( widget, plugin.guiPart->appName() ); } // set the order/activate tab conf.pluginManagement( plugin.name, plugin.guiPart->pluginName(), Resource::loadPixmap( plugin.guiPart->pixmapNameWidget() ) ); } if ( conf.exec() == QDialog::Accepted ) { conf.writeConfig(); ConfigWidget *confWidget; for ( confWidget = configWidgetList.first(); confWidget != 0; confWidget = configWidgetList.next() ) { confWidget->writeConfig(); } refresh(); } } /** * Refresh for the view. Reload all applets * */ void Today::refresh() { init(); + // set the date in top label + QDate date = QDate::currentDate(); + QString time = ( tr( date.toString() ) ); + + DateLabel->setText( QString( "<font color=#FFFFFF>" + time + "</font>" ) ); + if ( layout ) { delete layout; } layout = new QVBoxLayout( this ); layout->addWidget( Frame ); layout->addWidget( OwnerField ); loadPlugins(); draw(); } void Today::startAddressbook() { QCopEnvelope e( "QPE/System", "execute(QString)" ); e << QString( "addressbook" ); } /** * launch addressbook (personal card) */ void Today::editCard() { startAddressbook(); while( !QCopChannel::isRegistered( "QPE/Addressbook" ) ) { qApp->processEvents(); } QCopEnvelope v( "QPE/Addressbook", "editPersonalAndClose()" ); } Today::~Today() { } diff --git a/core/pim/today/today.h b/core/pim/today/today.h index 672adc4..b35c9b1 100644 --- a/core/pim/today/today.h +++ b/core/pim/today/today.h @@ -1,72 +1,73 @@ /* * today.h * * copyright : (c) 2002 by Maximilian Reiß * email : harlekin@handhelds.org * */ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef TODAY_H #define TODAY_H #include <opie/tododb.h> #include <qdatetime.h> #include <qlist.h> #include <qhbox.h> #include <qpe/qlibrary.h> #include <qpe/event.h> #include "todayconfig.h" #include "todaybase.h" #include "todayplugininterface.h" class QVBoxLayout; + class Today : public TodayBase { Q_OBJECT public: Today( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~Today(); private slots: void startConfig(); void startAddressbook(); void editCard(); void refresh(); private: void init(); void setOwnerField(); void setOwnerField(QString &string); void loadPlugins(); void draw(); - private slots: void channelReceived(const QCString &msg, const QByteArray & data); private: TodayConfig *conf; QStringList m_excludeApplets; + QStringList m_allApplets; // QString m_autoStartTimer; int m_newStart; // int m_autoStart; int m_maxCharClip; }; #endif diff --git a/core/pim/today/todayconfig.cpp b/core/pim/today/todayconfig.cpp index 4f23471..532d126 100644 --- a/core/pim/today/todayconfig.cpp +++ b/core/pim/today/todayconfig.cpp @@ -1,215 +1,220 @@ /* * todayconfig.cpp * * copyright : (c) 2002 by Maximilian Reiß * email : harlekin@handhelds.org * */ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "todayconfig.h" #include <qpe/config.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qcheckbox.h> #include <qlabel.h> #include <qspinbox.h> #include <qtabwidget.h> #include <qlayout.h> #include <qheader.h> #include <qhbox.h> #include <qvbox.h> #include <qtoolbutton.h> class ToolButton : public QToolButton { public: ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) : QToolButton( parent, name ) { - // setTextLabel( name ); setPixmap( Resource::loadPixmap( icon ) ); setAutoRaise( TRUE ); setFocusPolicy( QWidget::NoFocus ); setToggleButton( t ); connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); } }; /** * The class has currently quite some duplicate code. * By that way it would be real easy to have it as seperate app in settings tab * */ TodayConfig::TodayConfig( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { setCaption( tr( "Today config" ) ); QVBoxLayout *layout = new QVBoxLayout( this ); TabWidget3 = new QTabWidget( this, "TabWidget3" ); TabWidget3->setAutoMask( FALSE ); TabWidget3->setTabShape( QTabWidget::Rounded ); layout->addWidget( TabWidget3 ); tab_2 = new QWidget( TabWidget3, "tab_2" ); QVBoxLayout *tab2Layout = new QVBoxLayout( tab_2, 4 ,4 ); 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 ); QVBox *vbox1 = new QVBox( hbox1 ); new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", this , SLOT( moveSelectedUp() ) ); new ToolButton( vbox1, tr( "Move Down" ),"opieplayer/down", this , SLOT( moveSelectedDown() ) ); tab2Layout->addWidget( hbox1 ); - TabWidget3->insertTab( tab_2, tr( "active/order" ) ); + tab_3 = new QWidget( TabWidget3, "tab_3" ); QVBoxLayout *tab3Layout = new QVBoxLayout( tab_3 ); - QHBox *hbox_clip = new QHBox( tab_3 ); - TextLabel1 = new QLabel( hbox_clip, "TextLabel1" ); - TextLabel1->setText( tr( "Clip after how\n" - "many letters" ) ); - SpinBox7 = new QSpinBox( hbox_clip, "SpinBox7" ); - SpinBox7->setMaxValue( 80 ); + tab3Layout->setMargin( 20 ); QHBox *hbox_auto = new QHBox( tab_3 ); TextLabel2 = new QLabel( hbox_auto, "AutoStart" ); - TextLabel2->setText( tr( "autostart on \nresume? (Opie only)" ) ); + TextLabel2->setText( tr( "autostart on \nresume?\n (Opie only)" ) ); CheckBoxAuto = new QCheckBox( hbox_auto, "CheckBoxAuto" ); QHBox *hbox_inactive = new QHBox( tab_3 ); TimeLabel = new QLabel( hbox_inactive , "TimeLabel" ); TimeLabel->setText( tr( "minutes inactive" ) ); - SpinBoxTime = new QSpinBox( hbox_inactive, "TimeSpinner"); - tab3Layout->addWidget( hbox_clip ); + SpinBoxTime = new QSpinBox( hbox_inactive, "TimeSpinner" ); tab3Layout->addWidget( hbox_auto ); tab3Layout->addWidget( hbox_inactive ); TabWidget3->insertTab( tab_3, tr( "Misc" ) ); m_applets_changed = false; connect ( m_appletListView , SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( appletChanged ( ) ) ); readConfig(); showMaximized(); } /** * Autostart, uses the new (opie only) autostart method in the launcher code. * If registered against that today ist started on each resume. */ void TodayConfig::setAutoStart() { Config cfg( "today" ); cfg.setGroup( "Autostart" ); - int autostart = cfg.readNumEntry( "autostart", 1); + int autostart = cfg.readNumEntry( "autostart", 1 ); if ( autostart ) { QCopEnvelope e( "QPE/System", "autoStart(QString,QString,QString)" ); e << QString( "add" ); e << QString( "today" ); e << m_autoStartTimer; } else { QCopEnvelope e( "QPE/System", "autoStart(QString,QString)" ); e << QString( "remove" ); e << QString( "today" ); } } /** * Read the config part */ void TodayConfig::readConfig() { Config cfg( "today" ); cfg.setGroup( "Autostart" ); m_autoStart = cfg.readNumEntry( "autostart", 1 ); CheckBoxAuto->setChecked( m_autoStart ); m_autoStartTimer = cfg.readEntry( "autostartdelay", "0" ); SpinBoxTime->setValue( m_autoStartTimer.toInt() ); - cfg.setGroup( "Applets" ); + cfg.setGroup( "Plugins" ); m_excludeApplets = cfg.readListEntry( "ExcludeApplets", ',' ); } /** * Write the config part */ void TodayConfig::writeConfig() { Config cfg( "today" ); - cfg. setGroup ( "Applets" ); + cfg.setGroup( "Plugins" ); if ( m_applets_changed ) { QStringList exclude; QStringList include; - QMap <QString, QCheckListItem *>::Iterator it; - for ( it = m_applets.begin(); it != m_applets. end (); ++it ) { - if ( !(*it)-> isOn () ) { - exclude << it.key(); - } else { - include << it.key(); + QStringList all_applets; + + QListViewItemIterator list_it( m_appletListView ); + + // this makes sure the names get saved in the order selected + for ( ; list_it.current(); ++list_it ) { + QMap <QString, QCheckListItem *>::Iterator it; + for ( it = m_applets.begin(); it != m_applets. end (); ++it ) { + if ( list_it.current() == (*it) && !(*it)-> isOn () ) { + exclude << it.key(); + } else if ( list_it.current() == (*it) && (*it)-> isOn () ){ + include << it.key(); + } + if ( list_it.current() == (*it) ) { + all_applets << it.key(); + } } } cfg.writeEntry( "ExcludeApplets", exclude, ',' ); cfg.writeEntry( "IncludeApplets", include, ',' ); + cfg.writeEntry( "AllApplets", all_applets, ',' ); } cfg.setGroup( "Autostart" ); m_autoStart = CheckBoxAuto->isChecked(); - cfg.writeEntry( "autostart", m_autoStart ); + cfg.writeEntry( "autostart", m_autoStart ); m_autoStartTimer = SpinBoxTime->value(); cfg.readEntry( "autostartdelay", m_autoStartTimer ); } void TodayConfig::moveSelectedUp() { QListViewItem *item = m_appletListView->selectedItem(); - if ( item && item->itemAbove() ) { + 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 */ void TodayConfig::pluginManagement( QString libName, QString name, QPixmap icon ) { QCheckListItem *item; item = new QCheckListItem( m_appletListView, name, QCheckListItem::CheckBox ); if ( !icon.isNull() ) { item->setPixmap( 0, icon ); } - qDebug (" SUCHNAME: " + name ); if ( m_excludeApplets.find( libName ) == m_excludeApplets.end() ) { item->setOn( TRUE ); } + m_applets[libName] = item; } void TodayConfig::appletChanged() { m_applets_changed = true; } TodayConfig::~TodayConfig() { } |