summaryrefslogtreecommitdiff
path: root/library/categoryselect.cpp
Unidiff
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
@@ -21,6 +21,8 @@
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
@@ -29,2 +31,10 @@
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
@@ -59,3 +69,3 @@ public:
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 )
@@ -63,2 +73,4 @@ CategoryCombo::CategoryCombo( QWidget *parent, const char *name )
63 d = new CategoryComboPrivate(this); 73 d = new CategoryComboPrivate(this);
74 if (width)
75 setFixedWidth(width);
64} 76}
@@ -80,2 +92,5 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
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)),
@@ -84,3 +99,4 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
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
@@ -96,5 +112,3 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
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...
@@ -113,2 +127,3 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
113 } 127 }
128 insertItem( *it );
114 } else 129 } else
@@ -119,3 +134,95 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
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;
@@ -124,7 +231,13 @@ void CategoryCombo::initCombo( const QArray<int> &recCats,
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()
@@ -138,4 +251,4 @@ int CategoryCombo::currentCategory() const
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;
@@ -144,3 +257,3 @@ int CategoryCombo::currentCategory() const
144 else 257 else
145 returnMe = d->mAppCats[returnMe - 1]; 258 returnMe = d->mAppCats[returnMe];
146 return returnMe; 259 return returnMe;
@@ -175,3 +288,3 @@ void CategoryCombo::slotValueChanged( int )
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 ),
@@ -182,3 +295,3 @@ CategorySelect::CategorySelect( QWidget *parent, const char *name )
182 d = new CategorySelectPrivate(); 295 d = new CategorySelectPrivate();
183 init(); 296 init(width);
184} 297}
@@ -187,3 +300,3 @@ CategorySelect::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 )
@@ -191,3 +304,5 @@ CategorySelect::CategorySelect( const QArray<int> &vl,
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 );
@@ -198,3 +313,3 @@ CategorySelect::CategorySelect( const QArray<int> &vl,
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 )
@@ -202,3 +317,3 @@ CategorySelect::CategorySelect( const QArray<int> &vl,
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 );
@@ -213,2 +328,13 @@ void 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 );
@@ -228,2 +354,5 @@ void CategorySelect::slotDialog()
228 } 354 }
355
356 f.close();
357 QFile::remove( categoryEdittingFileName() );
229} 358}
@@ -249,9 +378,9 @@ void CategorySelect::slotNewCat( int newUid )
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,
@@ -259,11 +388,12 @@ void CategorySelect::setCategories( const QArray<int> &rec,
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)),
@@ -315 +445,8 @@ void CategorySelect::setAllCategories( bool add )
315} 445}
446
447// 01.12.21 added
448void CategorySelect::setFixedWidth(int width)
449{
450 width -= cmdCat->width();
451 cmbCat->setFixedWidth(width);
452}