summaryrefslogtreecommitdiff
authorerik <erik>2007-01-10 16:52:08 (UTC)
committer erik <erik>2007-01-10 16:52:08 (UTC)
commit51bd5e8d542372ad54898ce642fe9b82b8ba83f3 (patch) (unidiff)
treef2d6649a26347239e992082b22deca343939fc33
parent3c4c894bcdb1e49ce4d3e8167c8a21b1c617037d (diff)
downloadopie-51bd5e8d542372ad54898ce642fe9b82b8ba83f3.zip
opie-51bd5e8d542372ad54898ce642fe9b82b8ba83f3.tar.gz
opie-51bd5e8d542372ad54898ce642fe9b82b8ba83f3.tar.bz2
BUG: If the global category is checked in the category dialog the
'New Category' entry is still in local application scope. This means that the 'New Category' entry is in the wrong scope and all hell breaks loose. Actually the user will probably get confused that the category they are wanting to change is not in the right scope. FIX: Check to see that the global checkbox is checked before trying to add the new category. NOTE: This patch was originally submitted by Paul Eggleton (Blue Lightning). Thanks for the fix!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/categoryedit_p.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/library/categoryedit_p.cpp b/library/categoryedit_p.cpp
index 14ac2e1..ee0da22 100644
--- a/library/categoryedit_p.cpp
+++ b/library/categoryedit_p.cpp
@@ -1,227 +1,230 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "categoryedit_p.h" 21#include "categoryedit_p.h"
22 22
23#include <qpe/categories.h> 23#include <qpe/categories.h>
24 24
25#include <qdir.h> 25#include <qdir.h>
26#include <qcheckbox.h> 26#include <qcheckbox.h>
27#include <qlineedit.h> 27#include <qlineedit.h>
28 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31 31
32#include <stdlib.h> 32#include <stdlib.h>
33 33
34 34
35using namespace Qtopia; 35using namespace Qtopia;
36 36
37class CategoryEditPrivate 37class CategoryEditPrivate
38{ 38{
39public: 39public:
40 CategoryEditPrivate( QWidget *parent, const QString &appName ) 40 CategoryEditPrivate( QWidget *parent, const QString &appName )
41 : mCategories( parent, "" ), 41 : mCategories( parent, "" ),
42 mStrApp( appName ) 42 mStrApp( appName )
43 { 43 {
44 editItem = 0; 44 editItem = 0;
45 mCategories.load( categoryFileName() ); 45 mCategories.load( categoryFileName() );
46 } 46 }
47 Categories mCategories; 47 Categories mCategories;
48 QListViewItem *editItem; 48 QListViewItem *editItem;
49 QString mStrApp; 49 QString mStrApp;
50 QString mVisible; 50 QString mVisible;
51}; 51};
52 52
53CategoryEdit::CategoryEdit( QWidget *parent, const char *name ) 53CategoryEdit::CategoryEdit( QWidget *parent, const char *name )
54 : CategoryEditBase( parent, name ) 54 : CategoryEditBase( parent, name )
55{ 55{
56 d = 0; 56 d = 0;
57} 57}
58 58
59CategoryEdit::CategoryEdit( const QArray<int> &recCats, 59CategoryEdit::CategoryEdit( const QArray<int> &recCats,
60 const QString &appName, const QString &visibleName, 60 const QString &appName, const QString &visibleName,
61 QWidget *parent, const char *name ) 61 QWidget *parent, const char *name )
62 : CategoryEditBase( parent, name ) 62 : CategoryEditBase( parent, name )
63{ 63{
64 d = 0; 64 d = 0;
65 setCategories( recCats, appName, visibleName ); 65 setCategories( recCats, appName, visibleName );
66} 66}
67 67
68void CategoryEdit::setCategories( const QArray<int> &recCats, 68void CategoryEdit::setCategories( const QArray<int> &recCats,
69 const QString &appName, const QString &visibleName ) 69 const QString &appName, const QString &visibleName )
70{ 70{
71 if ( !d ) 71 if ( !d )
72 d = new CategoryEditPrivate( (QWidget*)parent(), name() ); 72 d = new CategoryEditPrivate( (QWidget*)parent(), name() );
73 d->mStrApp = appName; 73 d->mStrApp = appName;
74 d->mVisible = visibleName; 74 d->mVisible = visibleName;
75 75
76 QStringList appCats = d->mCategories.labels( d->mStrApp ); 76 QStringList appCats = d->mCategories.labels( d->mStrApp );
77 QArray<int> cats = d->mCategories.ids(d->mStrApp, appCats); 77 QArray<int> cats = d->mCategories.ids(d->mStrApp, appCats);
78 lvView->clear(); 78 lvView->clear();
79 79
80 QStringList::ConstIterator it; 80 QStringList::ConstIterator it;
81 int i, j; 81 int i, j;
82 for ( i = 0, it = appCats.begin(); it != appCats.end(); i++, ++it ) { 82 for ( i = 0, it = appCats.begin(); it != appCats.end(); i++, ++it ) {
83 QCheckListItem *chk; 83 QCheckListItem *chk;
84 chk = new QCheckListItem( lvView, (*it), QCheckListItem::CheckBox ); 84 chk = new QCheckListItem( lvView, (*it), QCheckListItem::CheckBox );
85 if ( !d->mCategories.isGlobal((*it)) ) 85 if ( !d->mCategories.isGlobal((*it)) )
86 chk->setText( 1, tr(d->mVisible) ); 86 chk->setText( 1, tr(d->mVisible) );
87 else 87 else
88 chk->setText( 1, tr("All") ); 88 chk->setText( 1, tr("All") );
89 // Is this record using this category, then we should check it 89 // Is this record using this category, then we should check it
90 for ( j = 0; j < int(recCats.count()); j++ ) { 90 for ( j = 0; j < int(recCats.count()); j++ ) {
91 if ( cats[i] == recCats[j] ) { 91 if ( cats[i] == recCats[j] ) {
92 chk->setOn( true ); 92 chk->setOn( true );
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 lvView->setSorting( 0, TRUE ); 97 lvView->setSorting( 0, TRUE );
98 lvView->sort(); 98 lvView->sort();
99 if ( lvView->childCount() < 1 ) 99 if ( lvView->childCount() < 1 )
100 txtCat->setEnabled( FALSE ); 100 txtCat->setEnabled( FALSE );
101 else { 101 else {
102 lvView->setSelected( lvView->firstChild(), true ); 102 lvView->setSelected( lvView->firstChild(), true );
103 } 103 }
104} 104}
105 105
106CategoryEdit::~CategoryEdit() 106CategoryEdit::~CategoryEdit()
107{ 107{
108 if ( d ) 108 if ( d )
109 delete d; 109 delete d;
110} 110}
111 111
112void CategoryEdit::slotSetText( QListViewItem *selected ) 112void CategoryEdit::slotSetText( QListViewItem *selected )
113{ 113{
114 d->editItem = selected; 114 d->editItem = selected;
115 if ( !d->editItem ) 115 if ( !d->editItem )
116 return; 116 return;
117 txtCat->setText( d->editItem->text(0) ); 117 txtCat->setText( d->editItem->text(0) );
118 txtCat->setEnabled( true ); 118 txtCat->setEnabled( true );
119 if ( d->editItem->text(1) == tr("All") ) 119 if ( d->editItem->text(1) == tr("All") )
120 chkGlobal->setChecked( true ); 120 chkGlobal->setChecked( true );
121 else 121 else
122 chkGlobal->setChecked( false ); 122 chkGlobal->setChecked( false );
123} 123}
124 124
125void CategoryEdit::slotAdd() 125void CategoryEdit::slotAdd()
126{ 126{
127 QString name = tr( "New Category" ); 127 QString name = tr( "New Category" );
128 bool insertOk = FALSE; 128 int uid = 0;
129 int num = 0; 129 int num = 0;
130 while ( !insertOk ) { 130 while ( !uid ) {
131 if ( num++ > 0 ) 131 if ( num++ > 0 )
132 name = tr("New Category ") + QString::number(num); 132 name = tr("New Category ") + QString::number(num);
133 insertOk = d->mCategories.addCategory( d->mStrApp, name ); 133 if ( chkGlobal->isChecked() )
134 uid = d->mCategories.addGlobalCategory( name );
135 else
136 uid = d->mCategories.addCategory( d->mStrApp, name );
134 } 137 }
135 QCheckListItem *chk; 138 QCheckListItem *chk;
136 chk = new QCheckListItem( lvView, name, QCheckListItem::CheckBox ); 139 chk = new QCheckListItem( lvView, name, QCheckListItem::CheckBox );
137 if ( !chkGlobal->isChecked() ) 140 if ( !chkGlobal->isChecked() )
138 chk->setText( 1, tr(d->mVisible) ); 141 chk->setText( 1, tr(d->mVisible) );
139 else 142 else
140 chk->setText( 1, tr("All") ); 143 chk->setText( 1, tr("All") );
141 144
142 lvView->setSelected( chk, TRUE ); 145 lvView->setSelected( chk, TRUE );
143 txtCat->selectAll(); 146 txtCat->selectAll();
144 txtCat->setFocus(); 147 txtCat->setFocus();
145} 148}
146 149
147void CategoryEdit::slotRemove() 150void CategoryEdit::slotRemove()
148{ 151{
149 d->editItem = lvView->selectedItem(); 152 d->editItem = lvView->selectedItem();
150 if ( d->editItem ) { 153 if ( d->editItem ) {
151 QListViewItem *sibling = d->editItem->nextSibling(); 154 QListViewItem *sibling = d->editItem->nextSibling();
152 155
153 d->mCategories.removeCategory( d->mStrApp, d->editItem->text(0) ); 156 d->mCategories.removeCategory( d->mStrApp, d->editItem->text(0) );
154 157
155 delete d->editItem; 158 delete d->editItem;
156 d->editItem = 0; 159 d->editItem = 0;
157 160
158 if ( sibling ) 161 if ( sibling )
159 lvView->setSelected( sibling, TRUE ); 162 lvView->setSelected( sibling, TRUE );
160 } 163 }
161 if ( lvView->childCount() < 1 ) { 164 if ( lvView->childCount() < 1 ) {
162 txtCat->clear(); 165 txtCat->clear();
163 txtCat->setEnabled( FALSE ); 166 txtCat->setEnabled( FALSE );
164 } 167 }
165} 168}
166 169
167void CategoryEdit::slotSetGlobal( bool isChecked ) 170void CategoryEdit::slotSetGlobal( bool isChecked )
168{ 171{
169 if ( d->editItem ) { 172 if ( d->editItem ) {
170 if ( isChecked ) 173 if ( isChecked )
171 d->editItem->setText( 1, tr("All") ); 174 d->editItem->setText( 1, tr("All") );
172 else 175 else
173 d->editItem->setText( 1, tr(d->mVisible) ); 176 d->editItem->setText( 1, tr(d->mVisible) );
174 177
175 d->mCategories.setGlobal( d->mStrApp, d->editItem->text( 0 ), isChecked ); 178 d->mCategories.setGlobal( d->mStrApp, d->editItem->text( 0 ), isChecked );
176 } 179 }
177} 180}
178 181
179void CategoryEdit::slotTextChanged( const QString &strNew ) 182void CategoryEdit::slotTextChanged( const QString &strNew )
180{ 183{
181 if ( d->editItem ) { 184 if ( d->editItem ) {
182 if ( chkGlobal->isChecked() ) 185 if ( chkGlobal->isChecked() )
183 d->mCategories.renameGlobalCategory( d->editItem->text(0), strNew ); 186 d->mCategories.renameGlobalCategory( d->editItem->text(0), strNew );
184 else 187 else
185 d->mCategories.renameCategory( d->mStrApp, d->editItem->text(0), strNew ); 188 d->mCategories.renameCategory( d->mStrApp, d->editItem->text(0), strNew );
186 d->editItem->setText( 0, strNew ); 189 d->editItem->setText( 0, strNew );
187 } 190 }
188} 191}
189 192
190QArray<int> CategoryEdit::newCategories() 193QArray<int> CategoryEdit::newCategories()
191{ 194{
192 QArray<int> a; 195 QArray<int> a;
193 if ( d ) { 196 if ( d ) {
194 d->mCategories.save( categoryFileName() ); 197 d->mCategories.save( categoryFileName() );
195 QListViewItemIterator it( lvView ); 198 QListViewItemIterator it( lvView );
196 QValueList<int> l; 199 QValueList<int> l;
197 for ( ; it.current(); ++it ) { 200 for ( ; it.current(); ++it ) {
198 if ( reinterpret_cast<QCheckListItem*>(it.current())->isOn() ) 201 if ( reinterpret_cast<QCheckListItem*>(it.current())->isOn() )
199 l.append( d->mCategories.id( d->mStrApp, it.current()->text(0) ) ); 202 l.append( d->mCategories.id( d->mStrApp, it.current()->text(0) ) );
200 } 203 }
201 uint i = 0; 204 uint i = 0;
202 a.resize( l.count() ); 205 a.resize( l.count() );
203 for ( QValueList<int>::Iterator lit = l.begin(); lit != l.end(); ++lit ) 206 for ( QValueList<int>::Iterator lit = l.begin(); lit != l.end(); ++lit )
204 a[i++] = *lit; 207 a[i++] = *lit;
205 } 208 }
206 return a; 209 return a;
207} 210}
208 211
209void CategoryEdit::accept() 212void CategoryEdit::accept()
210{ 213{
211 // write our categories out... 214 // write our categories out...
212 d->mCategories.save( categoryFileName() ); 215 d->mCategories.save( categoryFileName() );
213 // QDialog::accept(); 216 // QDialog::accept();
214} 217}
215 218
216QString categoryFileName() 219QString categoryFileName()
217{ 220{
218 QDir dir = (QString(getenv("HOME")) + "/Settings"); 221 QDir dir = (QString(getenv("HOME")) + "/Settings");
219 if ( !dir.exists() ) 222 if ( !dir.exists() )
220 mkdir( dir.path().local8Bit(), 0700 ); 223 mkdir( dir.path().local8Bit(), 0700 );
221 return dir.path() + "/" + "Categories" + ".xml"; 224 return dir.path() + "/" + "Categories" + ".xml";
222} 225}
223 226
224void CategoryEdit::kludge() 227void CategoryEdit::kludge()
225{ 228{
226 lvView->setMaximumHeight( 130 ); 229 lvView->setMaximumHeight( 130 );
227} 230}