summaryrefslogtreecommitdiff
path: root/library/categoryselect.cpp
authorkergoth <kergoth>2002-06-07 18:53:14 (UTC)
committer kergoth <kergoth>2002-06-07 18:53:14 (UTC)
commit640d964cfdc7467f6cacb513087cd3acda2c04f0 (patch) (unidiff)
tree9a784686c1795f8b1f81eb344598f3b549d43467 /library/categoryselect.cpp
parentdfb9c76738bb68e235114c5ad43dbd26a59b98ab (diff)
downloadopie-640d964cfdc7467f6cacb513087cd3acda2c04f0.zip
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.gz
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.bz2
Backing out unintentional merge from TT branch.
Diffstat (limited to 'library/categoryselect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/categoryselect.cpp185
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
@@ -19,14 +19,24 @@
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/categories.h> 21#include <qpe/categories.h>
22#include <qpe/palmtoprecord.h>
22 23
23#include <qdialog.h> 24#include <qmessagebox.h>
24#include <qlayout.h> 25#include <qlayout.h>
25#include <qtoolbutton.h> 26#include <qtoolbutton.h>
27#include <qfile.h>
26 28
27#include "categorywidget.h" 29#include "categorywidget.h"
28#include "categoryselect.h" 30#include "categoryselect.h"
29 31
32#include <stdlib.h>
33
34static QString categoryEdittingFileName()
35{
36 QString str = getenv("HOME");
37 str +="/.cateditting";
38 return str;
39}
30 40
31class CategoryComboPrivate 41class CategoryComboPrivate
32{ 42{
@@ -57,10 +67,12 @@ public:
57 QString mVisibleName; 67 QString mVisibleName;
58}; 68};
59 69
60CategoryCombo::CategoryCombo( QWidget *parent, const char *name ) 70CategoryCombo::CategoryCombo( QWidget *parent, const char *name , int width)
61 : QComboBox( parent, name ) 71 : QComboBox( parent, name )
62{ 72{
63 d = new CategoryComboPrivate(this); 73 d = new CategoryComboPrivate(this);
74 if (width)
75 setFixedWidth(width);
64} 76}
65 77
66void CategoryCombo::initCombo( const QArray<int> &recCats, 78void CategoryCombo::initCombo( const QArray<int> &recCats,
@@ -78,11 +90,15 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
78 clear(); 90 clear();
79 QStringList slApp; 91 QStringList slApp;
80 92
93 QObject::disconnect( this, SIGNAL(activated(int)),
94 this, SLOT(slotValueChanged(int)) );
95
81 QObject::connect( this, SIGNAL(activated(int)), 96 QObject::connect( this, SIGNAL(activated(int)),
82 this, SLOT(slotValueChanged(int)) ); 97 this, SLOT(slotValueChanged(int)) );
83 bool loadOk = d->mCat.load( categoryFileName() ); 98 bool loadOk = d->mCat.load( categoryFileName() );
84 slApp = d->mCat.labels( d->mStrAppName, TRUE, Categories::UnfiledLabel ); 99 slApp = d->mCat.labels( d->mStrAppName, TRUE, Categories::UnfiledLabel );
85 d->mAppCats = d->mCat.ids( d->mStrAppName ); 100
101 d->mAppCats = d->mCat.ids( d->mStrAppName, slApp);
86 102
87 int i, 103 int i,
88 j, 104 j,
@@ -94,9 +110,7 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
94 saveMe = -1; 110 saveMe = -1;
95 if ( recCount > 1 && loadOk ) { 111 if ( recCount > 1 && loadOk ) {
96 it = slApp.begin(); 112 it = slApp.begin();
97 insertItem( *it ); 113 for ( j = 0; j< (int)(slApp.count()-1); ++it, j++ ) {
98 ++it;
99 for ( j = 0; it != slApp.end(); ++it, j++ ) {
100 // grr... we have to go through and compare... 114 // grr... we have to go through and compare...
101 if ( j < int(d->mAppCats.size()) ) { 115 if ( j < int(d->mAppCats.size()) ) {
102 for ( i = 0; i < recCount; i++ ) { 116 for ( i = 0; i < recCount; i++ ) {
@@ -111,22 +125,121 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
111 } 125 }
112 insertItem( *it ); 126 insertItem( *it );
113 } 127 }
128 insertItem( *it );
114 } else 129 } else
115 insertStringList( slApp ); 130 insertStringList( slApp );
116 131
117 if ( recCount > 0 && loadOk ) { 132 if ( recCount > 0 && loadOk ) {
118 for ( i = 0; i < int(d->mAppCats.size()); i++ ) { 133 for ( i = 0; i < int(d->mAppCats.size()); i++ ) {
119 if ( d->mAppCats[i] == recCats[0] ) { 134 if ( d->mAppCats[i] == recCats[0] ) {
120 setCurrentItem( i + 1 ); 135 setCurrentItem( i );
136 break;
137 }
138 }
139 } else
140 {
141 setCurrentItem( slApp.count()-1 ); // unfiled
142 }
143}
144
145// this is a new function by SHARP instead of initCombo()
146QArray<int> CategoryCombo::initComboWithRefind( const QArray<int> &recCats,
147 const QString &appName)
148{
149 QString visibleName = appName;
150 d->mStrAppName = appName;
151 d->mStrVisibleName = visibleName;
152 clear();
153 QStringList slApp;
154 QArray<int> results;
155
156 QObject::disconnect( this, SIGNAL(activated(int)),
157 this, SLOT(slotValueChanged(int)) );
158
159 QObject::connect( this, SIGNAL(activated(int)),
160 this, SLOT(slotValueChanged(int)) );
161 bool loadOk = d->mCat.load( categoryFileName() );
162 slApp = d->mCat.labels( d->mStrAppName, TRUE, Categories::UnfiledLabel );
163
164 d->mAppCats = d->mCat.ids( d->mStrAppName, slApp);
165
166 // addition part
167 // make new recCats
168 if (loadOk){
169 int i,j;
170 int value;
171 int rCount = recCats.count();
172 int mCount = d->mAppCats.count();
173
174 for (i=0; i<rCount; i++){
175 value = 0;
176 for (j=0; j<mCount; j++){
177 if (recCats[i] == d->mAppCats[j]){
178 value = recCats[i];
179 break;
180 }
181 }
182 if (value != 0){
183 int tmp = results.size();
184 results.resize( tmp + 1 );
185 results[ tmp ] = value;
186 }
187 }
188 }
189 else{
190 results = recCats;
191 }
192 // addition end
193
194 int i,
195 j,
196 saveMe,
197 recCount;
198 QStringList::Iterator it;
199 // now add in all the items...
200 recCount = results.count();
201 saveMe = -1;
202 if ( recCount > 1 && loadOk ) {
203 it = slApp.begin();
204 for ( j = 0; j< (int)(slApp.count()-1); ++it, j++ ) {
205
206 // grr... we have to go through and compare...
207 if ( j < int(d->mAppCats.size()) ) {
208 for ( i = 0; i < recCount; i++ ) {
209 if ( results[i] == d->mAppCats[j] ) {
210 (*it).append( tr(" (Multi.)") );
211 if ( saveMe < 0 )
212 saveMe = j;
213 // no need to continue through the list.
214 break;
215 }
216 }
217 }
218 insertItem( *it );
219 }
220 insertItem( *it );
221 } else
222 insertStringList( slApp );
223
224 if ( recCount > 0 && loadOk ) {
225 for ( i = 0; i < int(d->mAppCats.size()); i++ ) {
226 if ( d->mAppCats[i] == results[0] ) {
227 setCurrentItem( i );
121 break; 228 break;
122 } 229 }
123 } 230 }
124 } else 231 } else
125 setCurrentItem( 0 ); // unfiled 232 {
233 setCurrentItem( slApp.count()-1 ); // unfiled
234 }
235/*
126 QObject::connect( this, SIGNAL(activated(int)), 236 QObject::connect( this, SIGNAL(activated(int)),
127 this, SLOT(slotValueChanged(int)) ); 237 this, SLOT(slotValueChanged(int)) );
238*/
239 return results;
128} 240}
129 241
242
130CategoryCombo::~CategoryCombo() 243CategoryCombo::~CategoryCombo()
131{ 244{
132 delete d; 245 delete d;
@@ -136,13 +249,13 @@ int CategoryCombo::currentCategory() const
136{ 249{
137 int returnMe; 250 int returnMe;
138 returnMe = currentItem(); 251 returnMe = currentItem();
139 // unfiled is now 0... 252
140 if ( returnMe == 0 ) 253 if ( returnMe == (int)d->mAppCats.count() )
141 returnMe = -1; 254 returnMe = -1;
142 else if ( returnMe > (int)d->mAppCats.count() ) // only happen on "All" 255 else if ( returnMe > (int)d->mAppCats.count() ) // only happen on "All"
143 returnMe = -2; 256 returnMe = -2;
144 else 257 else
145 returnMe = d->mAppCats[returnMe - 1]; 258 returnMe = d->mAppCats[returnMe];
146 return returnMe; 259 return returnMe;
147} 260}
148 261
@@ -173,34 +286,36 @@ void CategoryCombo::slotValueChanged( int )
173 emit sigCatChanged( currentCategory() ); 286 emit sigCatChanged( currentCategory() );
174} 287}
175 288
176CategorySelect::CategorySelect( QWidget *parent, const char *name ) 289CategorySelect::CategorySelect( QWidget *parent, const char *name,int width)
177 : QHBox( parent, name ), 290 : QHBox( parent, name ),
178 cmbCat( 0 ), 291 cmbCat( 0 ),
179 cmdCat( 0 ), 292 cmdCat( 0 ),
180 d( 0 ) 293 d( 0 )
181{ 294{
182 d = new CategorySelectPrivate(); 295 d = new CategorySelectPrivate();
183 init(); 296 init(width);
184} 297}
185 298
186CategorySelect::CategorySelect( const QArray<int> &vl, 299CategorySelect::CategorySelect( const QArray<int> &vl,
187 const QString &appName, QWidget *parent, 300 const QString &appName, QWidget *parent,
188 const char *name ) 301 const char *name ,int width)
189 : QHBox( parent, name ) 302 : QHBox( parent, name )
190{ 303{
191 d = new CategorySelectPrivate( vl ); 304 d = new CategorySelectPrivate( vl );
192 init(); 305
306 init(width);
307
193 setCategories( vl, appName, appName ); 308 setCategories( vl, appName, appName );
194} 309}
195 310
196CategorySelect::CategorySelect( const QArray<int> &vl, 311CategorySelect::CategorySelect( const QArray<int> &vl,
197 const QString &appName, 312 const QString &appName,
198 const QString &visibleName, 313 const QString &visibleName,
199 QWidget *parent, const char *name ) 314 QWidget *parent, const char *name , int width)
200 : QHBox( parent, name ) 315 : QHBox( parent, name )
201{ 316{
202 d = new CategorySelectPrivate( vl ); 317 d = new CategorySelectPrivate( vl );
203 init(); 318 init(width);
204 setCategories( vl, appName, visibleName ); 319 setCategories( vl, appName, visibleName );
205} 320}
206 321
@@ -211,6 +326,17 @@ CategorySelect::~CategorySelect()
211 326
212void CategorySelect::slotDialog() 327void CategorySelect::slotDialog()
213{ 328{
329 if (QFile::exists( categoryEdittingFileName() )){
330 QMessageBox::warning(this,tr("Error"),
331 tr("Sorry, another application is\nediting categories.") );
332 return;
333 }
334
335 QFile f( categoryEdittingFileName() );
336 if ( !f.open( IO_WriteOnly) ){
337 return;
338 }
339
214 QDialog editDlg( this, 0, TRUE ); 340 QDialog editDlg( this, 0, TRUE );
215 editDlg.setCaption( tr("Edit Categories") ); 341 editDlg.setCaption( tr("Edit Categories") );
216 QVBoxLayout *vb = new QVBoxLayout( &editDlg ); 342 QVBoxLayout *vb = new QVBoxLayout( &editDlg );
@@ -226,6 +352,9 @@ void CategorySelect::slotDialog()
226 d->mRec = ce.newCategories(); 352 d->mRec = ce.newCategories();
227 cmbCat->initCombo( d->mRec, mStrAppName ); 353 cmbCat->initCombo( d->mRec, mStrAppName );
228 } 354 }
355
356 f.close();
357 QFile::remove( categoryEdittingFileName() );
229} 358}
230 359
231void CategorySelect::slotNewCat( int newUid ) 360void CategorySelect::slotNewCat( int newUid )
@@ -247,25 +376,26 @@ void CategorySelect::slotNewCat( int newUid )
247 emit signalSelected( currentCategory() ); 376 emit signalSelected( currentCategory() );
248} 377}
249 378
250void CategorySelect::setCategories( const QArray<int> &rec, 379QString CategorySelect::setCategories( const QArray<int> &rec,
251 const QString &appName ) 380 const QString &appName )
252{ 381{
253 setCategories( rec, appName, appName ); 382 return setCategories( rec, appName, appName );
254} 383}
255 384
256void CategorySelect::setCategories( const QArray<int> &rec, 385QString CategorySelect::setCategories( const QArray<int> &rec,
257 const QString &appName, 386 const QString &appName,
258 const QString &visibleName ) 387 const QString &visibleName )
259{ 388{
260 d->mRec = rec;
261 d->mVisibleName = visibleName; 389 d->mVisibleName = visibleName;
262 mStrAppName = appName; 390 mStrAppName = appName;
263 cmbCat->initCombo( rec, appName ); 391 d->mRec = cmbCat->initComboWithRefind( rec, appName );
392 return Qtopia::Record::idsToString(d->mRec);
264} 393}
265 394
266void CategorySelect::init() 395void CategorySelect::init(int width)
267{ 396{
268 cmbCat = new CategoryCombo( this ); 397 cmbCat = new CategoryCombo( this, 0, width);
398
269 QObject::connect( cmbCat, SIGNAL(sigCatChanged(int)), 399 QObject::connect( cmbCat, SIGNAL(sigCatChanged(int)),
270 this, SLOT(slotNewCat(int)) ); 400 this, SLOT(slotNewCat(int)) );
271 cmdCat = new QToolButton( this ); 401 cmdCat = new QToolButton( this );
@@ -313,3 +443,10 @@ void CategorySelect::setAllCategories( bool add )
313 } else 443 } else
314 cmbCat->removeItem( cmbCat->count() - 1 ); 444 cmbCat->removeItem( cmbCat->count() - 1 );
315} 445}
446
447// 01.12.21 added
448void CategorySelect::setFixedWidth(int width)
449{
450 width -= cmdCat->width();
451 cmbCat->setFixedWidth(width);
452}