-rw-r--r-- | library/categoryselect.cpp | 185 |
1 files changed, 161 insertions, 24 deletions
diff --git a/library/categoryselect.cpp b/library/categoryselect.cpp index dc5d1fa..21b3f91 100644 --- a/library/categoryselect.cpp +++ b/library/categoryselect.cpp @@ -21,6 +21,8 @@ #include <qpe/categories.h> +#include <qpe/palmtoprecord.h> -#include <qdialog.h> +#include <qmessagebox.h> #include <qlayout.h> #include <qtoolbutton.h> +#include <qfile.h> @@ -29,2 +31,10 @@ +#include <stdlib.h> + +static QString categoryEdittingFileName() +{ + QString str = getenv("HOME"); + str +="/.cateditting"; + return str; +} @@ -59,3 +69,3 @@ public: -CategoryCombo::CategoryCombo( QWidget *parent, const char *name ) +CategoryCombo::CategoryCombo( QWidget *parent, const char *name , int width) : QComboBox( parent, name ) @@ -63,2 +73,4 @@ CategoryCombo::CategoryCombo( QWidget *parent, const char *name ) d = new CategoryComboPrivate(this); + if (width) + setFixedWidth(width); } @@ -80,2 +92,5 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, + QObject::disconnect( this, SIGNAL(activated(int)), + this, SLOT(slotValueChanged(int)) ); + QObject::connect( this, SIGNAL(activated(int)), @@ -84,3 +99,4 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, slApp = d->mCat.labels( d->mStrAppName, TRUE, Categories::UnfiledLabel ); - d->mAppCats = d->mCat.ids( d->mStrAppName ); + + d->mAppCats = d->mCat.ids( d->mStrAppName, slApp); @@ -96,5 +112,3 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, it = slApp.begin(); - insertItem( *it ); - ++it; - for ( j = 0; it != slApp.end(); ++it, j++ ) { + for ( j = 0; j< (int)(slApp.count()-1); ++it, j++ ) { // grr... we have to go through and compare... @@ -113,2 +127,3 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, } + insertItem( *it ); } else @@ -119,3 +134,3 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, if ( d->mAppCats[i] == recCats[0] ) { - setCurrentItem( i + 1 ); + setCurrentItem( i ); break; @@ -124,6 +139,104 @@ void CategoryCombo::initCombo( const QArray<int> &recCats, } else - setCurrentItem( 0 ); // unfiled + { + setCurrentItem( slApp.count()-1 ); // unfiled + } +} + +// this is a new function by SHARP instead of initCombo() +QArray<int> CategoryCombo::initComboWithRefind( const QArray<int> &recCats, + const QString &appName) +{ + QString visibleName = appName; + d->mStrAppName = appName; + d->mStrVisibleName = visibleName; + clear(); + QStringList slApp; + QArray<int> results; + + QObject::disconnect( this, SIGNAL(activated(int)), + this, SLOT(slotValueChanged(int)) ); + QObject::connect( this, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int)) ); + bool loadOk = d->mCat.load( categoryFileName() ); + slApp = d->mCat.labels( d->mStrAppName, TRUE, Categories::UnfiledLabel ); + + d->mAppCats = d->mCat.ids( d->mStrAppName, slApp); + + // addition part + // make new recCats + if (loadOk){ + int i,j; + int value; + int rCount = recCats.count(); + int mCount = d->mAppCats.count(); + + for (i=0; i<rCount; i++){ + value = 0; + for (j=0; j<mCount; j++){ + if (recCats[i] == d->mAppCats[j]){ + value = recCats[i]; + break; + } + } + if (value != 0){ + int tmp = results.size(); + results.resize( tmp + 1 ); + results[ tmp ] = value; + } + } } + else{ + results = recCats; + } + // addition end + + int i, + j, + saveMe, + recCount; + QStringList::Iterator it; + // now add in all the items... + recCount = results.count(); + saveMe = -1; + if ( recCount > 1 && loadOk ) { + it = slApp.begin(); + for ( j = 0; j< (int)(slApp.count()-1); ++it, j++ ) { + + // grr... we have to go through and compare... + if ( j < int(d->mAppCats.size()) ) { + for ( i = 0; i < recCount; i++ ) { + if ( results[i] == d->mAppCats[j] ) { + (*it).append( tr(" (Multi.)") ); + if ( saveMe < 0 ) + saveMe = j; + // no need to continue through the list. + break; + } + } + } + insertItem( *it ); + } + insertItem( *it ); + } else + insertStringList( slApp ); + + if ( recCount > 0 && loadOk ) { + for ( i = 0; i < int(d->mAppCats.size()); i++ ) { + if ( d->mAppCats[i] == results[0] ) { + setCurrentItem( i ); + break; + } + } + } else + { + setCurrentItem( slApp.count()-1 ); // unfiled + } +/* + QObject::connect( this, SIGNAL(activated(int)), + this, SLOT(slotValueChanged(int)) ); +*/ + return results; +} + @@ -138,4 +251,4 @@ int CategoryCombo::currentCategory() const returnMe = currentItem(); - // unfiled is now 0... - if ( returnMe == 0 ) + + if ( returnMe == (int)d->mAppCats.count() ) returnMe = -1; @@ -144,3 +257,3 @@ int CategoryCombo::currentCategory() const else - returnMe = d->mAppCats[returnMe - 1]; + returnMe = d->mAppCats[returnMe]; return returnMe; @@ -175,3 +288,3 @@ void CategoryCombo::slotValueChanged( int ) -CategorySelect::CategorySelect( QWidget *parent, const char *name ) +CategorySelect::CategorySelect( QWidget *parent, const char *name,int width) : QHBox( parent, name ), @@ -182,3 +295,3 @@ CategorySelect::CategorySelect( QWidget *parent, const char *name ) d = new CategorySelectPrivate(); - init(); + init(width); } @@ -187,3 +300,3 @@ CategorySelect::CategorySelect( const QArray<int> &vl, const QString &appName, QWidget *parent, - const char *name ) + const char *name ,int width) : QHBox( parent, name ) @@ -191,3 +304,5 @@ CategorySelect::CategorySelect( const QArray<int> &vl, d = new CategorySelectPrivate( vl ); - init(); + + init(width); + setCategories( vl, appName, appName ); @@ -198,3 +313,3 @@ CategorySelect::CategorySelect( const QArray<int> &vl, const QString &visibleName, - QWidget *parent, const char *name ) + QWidget *parent, const char *name , int width) : QHBox( parent, name ) @@ -202,3 +317,3 @@ CategorySelect::CategorySelect( const QArray<int> &vl, d = new CategorySelectPrivate( vl ); - init(); + init(width); setCategories( vl, appName, visibleName ); @@ -213,2 +328,13 @@ void CategorySelect::slotDialog() { + if (QFile::exists( categoryEdittingFileName() )){ + QMessageBox::warning(this,tr("Error"), + tr("Sorry, another application is\nediting categories.") ); + return; + } + + QFile f( categoryEdittingFileName() ); + if ( !f.open( IO_WriteOnly) ){ + return; + } + QDialog editDlg( this, 0, TRUE ); @@ -228,2 +354,5 @@ void CategorySelect::slotDialog() } + + f.close(); + QFile::remove( categoryEdittingFileName() ); } @@ -249,9 +378,9 @@ void CategorySelect::slotNewCat( int newUid ) -void CategorySelect::setCategories( const QArray<int> &rec, +QString CategorySelect::setCategories( const QArray<int> &rec, const QString &appName ) { - setCategories( rec, appName, appName ); + return setCategories( rec, appName, appName ); } -void CategorySelect::setCategories( const QArray<int> &rec, +QString CategorySelect::setCategories( const QArray<int> &rec, const QString &appName, @@ -259,11 +388,12 @@ void CategorySelect::setCategories( const QArray<int> &rec, { - d->mRec = rec; d->mVisibleName = visibleName; mStrAppName = appName; - cmbCat->initCombo( rec, appName ); + d->mRec = cmbCat->initComboWithRefind( rec, appName ); + return Qtopia::Record::idsToString(d->mRec); } -void CategorySelect::init() +void CategorySelect::init(int width) { - cmbCat = new CategoryCombo( this ); + cmbCat = new CategoryCombo( this, 0, width); + QObject::connect( cmbCat, SIGNAL(sigCatChanged(int)), @@ -315 +445,8 @@ void CategorySelect::setAllCategories( bool add ) } + +// 01.12.21 added +void CategorySelect::setFixedWidth(int width) +{ + width -= cmdCat->width(); + cmbCat->setFixedWidth(width); +} |