summaryrefslogtreecommitdiff
authortille <tille>2002-06-30 01:05:42 (UTC)
committer tille <tille>2002-06-30 01:05:42 (UTC)
commit064b3d7b91a526a64c22facba228e3c2fec8fdc8 (patch) (unidiff)
tree98221da79a27bc13b8214b92c8c936c529312e24
parent1f9e13bb2d287a2495e2cbb0f8be0f53c883eae2 (diff)
downloadopie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.zip
opie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.tar.gz
opie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.tar.bz2
late night
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/confedit/listviewitemconf.cpp5
-rw-r--r--noncore/apps/confedit/listviewitemconf.h4
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp24
-rw-r--r--noncore/apps/confedit/listviewitemconffile.h8
-rw-r--r--noncore/apps/confedit/listviewitemconfigentry.cpp18
-rw-r--r--noncore/apps/confedit/listviewitemconfigentry.h5
-rw-r--r--noncore/apps/confedit/mainwindow.cpp65
-rw-r--r--noncore/apps/confedit/mainwindow.h4
8 files changed, 104 insertions, 29 deletions
diff --git a/noncore/apps/confedit/listviewitemconf.cpp b/noncore/apps/confedit/listviewitemconf.cpp
index 55f8422..91edca2 100644
--- a/noncore/apps/confedit/listviewitemconf.cpp
+++ b/noncore/apps/confedit/listviewitemconf.cpp
@@ -1,46 +1,51 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#include "listviewitemconf.h" 10#include "listviewitemconf.h"
11 11
12ListViewItemConf::ListViewItemConf(ListViewItemConf *parent) 12ListViewItemConf::ListViewItemConf(ListViewItemConf *parent)
13 : QListViewItem(parent), _changed(false) 13 : QListViewItem(parent), _changed(false)
14{ 14{
15} 15}
16 16
17ListViewItemConf::ListViewItemConf(QListView *parent) 17ListViewItemConf::ListViewItemConf(QListView *parent)
18 : QListViewItem(parent), _changed(false) 18 : QListViewItem(parent), _changed(false)
19{ 19{
20 _type = File; 20 _type = File;
21} 21}
22 22
23ListViewItemConf::~ListViewItemConf() 23ListViewItemConf::~ListViewItemConf()
24{ 24{
25} 25}
26 26
27int ListViewItemConf::getType() 27int ListViewItemConf::getType()
28{ 28{
29 return _type; 29 return _type;
30} 30}
31 31
32void ListViewItemConf::changed() 32void ListViewItemConf::changed()
33{ 33{
34 _changed=true; 34 _changed=true;
35 displayText(); 35 displayText();
36} 36}
37 37
38void ListViewItemConf::unchanged() 38void ListViewItemConf::unchanged()
39{ 39{
40 _changed=false; 40 _changed=false;
41 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) 41 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
42 { 42 {
43 ((ListViewItemConf*)it)->unchanged(); 43 ((ListViewItemConf*)it)->unchanged();
44 } 44 }
45 displayText(); 45 displayText();
46}
47
48bool ListViewItemConf::revertable()
49{
50 return _changed;
46} \ No newline at end of file 51} \ No newline at end of file
diff --git a/noncore/apps/confedit/listviewitemconf.h b/noncore/apps/confedit/listviewitemconf.h
index c6e60ba..3c504ed 100644
--- a/noncore/apps/confedit/listviewitemconf.h
+++ b/noncore/apps/confedit/listviewitemconf.h
@@ -1,36 +1,40 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#ifndef LISTVIEWITEMCONF_H 10#ifndef LISTVIEWITEMCONF_H
11#define LISTVIEWITEMCONF_H 11#define LISTVIEWITEMCONF_H
12 12
13#include <qlistview.h> 13#include <qlistview.h>
14 14
15 15
16class ListViewItemConf : public QListViewItem 16class ListViewItemConf : public QListViewItem
17{ 17{
18public: 18public:
19 enum {File, Group, Key}; 19 enum {File, Group, Key};
20 20
21 ListViewItemConf(ListViewItemConf *parent); 21 ListViewItemConf(ListViewItemConf *parent);
22 ListViewItemConf(QListView *parent); 22 ListViewItemConf(QListView *parent);
23 ~ListViewItemConf(); 23 ~ListViewItemConf();
24 24
25 int getType(); 25 int getType();
26 void save();
27 virtual void revert() = 0;
28 virtual void remove() = 0;
26 virtual void displayText() = 0; 29 virtual void displayText() = 0;
27 virtual void changed(); 30 virtual void changed();
28 bool isChanged() {return _changed;}; 31 bool isChanged() {return _changed;};
29 virtual void unchanged(); 32 virtual void unchanged();
33 virtual bool revertable();
30 34
31protected: 35protected:
32 int _type; 36 int _type;
33 bool _changed; 37 bool _changed;
34}; 38};
35 39
36#endif 40#endif
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp
index b075063..228421b 100644
--- a/noncore/apps/confedit/listviewitemconffile.cpp
+++ b/noncore/apps/confedit/listviewitemconffile.cpp
@@ -1,134 +1,142 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 9// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
10 10
11#include "listviewitemconffile.h" 11#include "listviewitemconffile.h"
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qtextstream.h> 13#include <qtextstream.h>
14#include <qstring.h> 14#include <qstring.h>
15#include "listviewitemconfigentry.h" 15#include "listviewitemconfigentry.h"
16 16
17#define tr QObject::tr 17#define tr QObject::tr
18 18
19ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) 19ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent)
20 : ListViewItemConf(parent), _valid(false) 20 : ListViewItemConf(parent), _valid(false)
21{ 21{
22 confFileInfo = file; 22 confFileInfo = file;
23 parseFile(); 23 parseFile();
24 displayText(); 24 displayText();
25} 25}
26 26
27ListViewItemConfFile::~ListViewItemConfFile() 27ListViewItemConfFile::~ListViewItemConfFile()
28{ 28{
29} 29}
30 30
31 31
32void ListViewItemConfFile::displayText() 32void ListViewItemConfFile::displayText()
33{ 33{
34 setText(0,(_changed?"*":"")+confFileInfo->fileName()); 34 setText(0,(_changed?"*":"")+confFileInfo->fileName());
35} 35}
36 36
37QString ListViewItemConfFile::fileName() 37QString ListViewItemConfFile::fileName()
38{ 38{
39 return confFileInfo->fileName(); 39 return confFileInfo->fileName();
40} 40}
41 41
42void ListViewItemConfFile::parseFile() 42void ListViewItemConfFile::parseFile()
43{ 43{
44 QFile confFile(confFileInfo->absFilePath()); 44 QFile confFile(confFileInfo->absFilePath());
45 if(! confFile.open(IO_ReadOnly)) 45 if(! confFile.open(IO_ReadOnly))
46 QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); 46 QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0);
47 QTextStream t( &confFile ); 47 QTextStream t( &confFile );
48 QString s; 48 QString s;
49 QString group; 49 QString group;
50 ListViewItemConfigEntry *groupItem; 50 ListViewItemConfigEntry *groupItem;
51 ListViewItemConfigEntry *item; 51 ListViewItemConfigEntry *item;
52 while ( !t.atEnd() ) 52 while ( !t.atEnd() )
53 { 53 {
54 s = t.readLine().stripWhiteSpace(); 54 s = t.readLine().stripWhiteSpace();
55 //qDebug( "line: >%s<\n", s.latin1() ); 55 //qDebug( "line: >%s<\n", s.latin1() );
56 if (s.contains("<?xml")) 56 if (s.contains("<?xml"))
57 { 57 {
58 _valid = false; 58 _valid = false;
59 break; 59 break;
60 }else 60 }else
61 if ( s[0] == '[' && s[s.length()-1] == ']' ) 61 if ( s[0] == '[' && s[s.length()-1] == ']' )
62 { 62 {
63 // qDebug("got group"+s); 63 // qDebug("got group"+s);
64 group = s.mid(1,s.length()-2); 64 group = s.mid(1,s.length()-2);
65 groupItem = new ListViewItemConfigEntry(this, group ); 65 groupItem = new ListViewItemConfigEntry(this, group );
66 insertItem( groupItem ); 66 insertItem( groupItem );
67 } else 67 } else
68 if ( int pos = s.find('=') ) 68 if ( int pos = s.find('=') )
69 { 69 {
70 // qDebug("got key"+s); 70 // qDebug("got key"+s);
71 item = new ListViewItemConfigEntry(this, group, s ); 71 item = new ListViewItemConfigEntry(this, group, s );
72 groupItem->insertItem( item ); 72 groupItem->insertItem( item );
73 } 73 }
74 } 74 }
75 confFile.close(); 75 confFile.close();
76 unchanged(); 76 unchanged();
77 setExpandable( _valid ); 77 setExpandable( _valid );
78} 78}
79 79
80 80
81void ListViewItemConfFile::remove()
82{
83 QFile::remove(confFileInfo->absFilePath());
84 QFile::remove(backupFileName());
85 delete this;
86}
87
81void ListViewItemConfFile::revert() 88void ListViewItemConfFile::revert()
82{ 89{
83 if (_changed) 90 if (_changed)
84 { 91 {
85 parseFile(); 92 parseFile();
86 }else{ 93 }else{
87 QString backup = confFileInfo->absFilePath()+"~";
88 QFile conf(confFileInfo->absFilePath()); 94 QFile conf(confFileInfo->absFilePath());
89 QFile back(backup); 95 QFile back(backupFileName());
90 96
91 if (!back.open(IO_ReadOnly)) return; 97 if (!back.open(IO_ReadOnly)) return;
92 if (!conf.open(IO_WriteOnly)) return; 98 if (!conf.open(IO_WriteOnly)) return;
93 99
94 #define SIZE 124 100 #define SIZE 124
95 char buf[SIZE]; 101 char buf[SIZE];
96 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); 102 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c);
97 conf.close(); 103 conf.close();
98 back.close(); 104 back.close();
99 } 105 }
100} 106}
101 107
102void ListViewItemConfFile::save() 108void ListViewItemConfFile::save()
103{ 109{
104 if (!_changed) return; 110 if (!_changed) return;
105 QString backup = confFileInfo->absFilePath()+"~";
106 qDebug("make backup to "+backup);
107 QFile conf(confFileInfo->absFilePath()); 111 QFile conf(confFileInfo->absFilePath());
108 QFile back(backup); 112 QFile back(backupFileName());
109 113
110 if (!conf.open(IO_ReadOnly)) return; 114 if (!conf.open(IO_ReadOnly)) return;
111 if (!back.open(IO_WriteOnly)) return; 115 if (!back.open(IO_WriteOnly)) return;
112 116
113 #define SIZE 124
114 char buf[SIZE]; 117 char buf[SIZE];
115 while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); 118 while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c);
116 conf.close(); 119 conf.close();
117 back.close(); 120 back.close();
118 121
119 122
120 if (!conf.open(IO_WriteOnly)) return; 123 if (!conf.open(IO_WriteOnly)) return;
121 QTextStream *t = new QTextStream( &conf ); 124 QTextStream *t = new QTextStream( &conf );
122 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) 125 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
123 { 126 {
124 ((ListViewItemConfigEntry*)it)->save(t); 127 ((ListViewItemConfigEntry*)it)->save(t);
125 } 128 }
126 conf.close(); 129 conf.close();
127 unchanged(); 130 unchanged();
128} 131}
129 132
130 133
131bool ListViewItemConfFile::revertable() 134bool ListViewItemConfFile::revertable()
132{ 135{
133 return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); 136 return _changed || QFile(backupFileName()).exists();
134} \ No newline at end of file 137}
138
139QString ListViewItemConfFile::backupFileName()
140{
141 return confFileInfo->absFilePath()+"~";
142}
diff --git a/noncore/apps/confedit/listviewitemconffile.h b/noncore/apps/confedit/listviewitemconffile.h
index ae23eab..679a2ed 100644
--- a/noncore/apps/confedit/listviewitemconffile.h
+++ b/noncore/apps/confedit/listviewitemconffile.h
@@ -1,37 +1,39 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 // (c) 2002 Patrick S. Vogt <tille@handhelds.org> 9 // (c) 2002 Patrick S. Vogt <tille@handhelds.org>
10 10
11#ifndef LISTVIEWITEMCONFFILE_H 11#ifndef LISTVIEWITEMCONFFILE_H
12#define LISTVIEWITEMCONFFILE_H 12#define LISTVIEWITEMCONFFILE_H
13 13
14#include <qwidget.h> 14#include <qwidget.h>
15#include <qlistview.h> 15#include <qlistview.h>
16#include <qfile.h> 16#include <qfile.h>
17#include <qfileinfo.h> 17#include <qfileinfo.h>
18#include "listviewitemconf.h" 18#include "listviewitemconf.h"
19 19
20 20
21class ListViewItemConfFile : public ListViewItemConf { 21class ListViewItemConfFile : public ListViewItemConf {
22public: 22public:
23 ListViewItemConfFile(QFileInfo *file, QListView *parent=0); 23 ListViewItemConfFile(QFileInfo *file, QListView *parent=0);
24 ~ListViewItemConfFile(); 24 ~ListViewItemConfFile();
25 void parseFile(); 25 void parseFile();
26 QString fileName(); 26 QString fileName();
27 virtual void displayText();
28 bool revertable();
29 void save(); 27 void save();
30 void revert(); 28 virtual void displayText();
29 virtual bool revertable();
30 virtual void revert();
31 virtual void remove();
32 QString backupFileName();
31protected: 33protected:
32private: 34private:
33 bool _valid; 35 bool _valid;
34 QFileInfo *confFileInfo; 36 QFileInfo *confFileInfo;
35}; 37};
36 38
37#endif 39#endif
diff --git a/noncore/apps/confedit/listviewitemconfigentry.cpp b/noncore/apps/confedit/listviewitemconfigentry.cpp
index 77ce17d..b947514 100644
--- a/noncore/apps/confedit/listviewitemconfigentry.cpp
+++ b/noncore/apps/confedit/listviewitemconfigentry.cpp
@@ -1,128 +1,146 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 // (c) 2002 Patrick S. Vogtp <tille@handhelds.org> 9 // (c) 2002 Patrick S. Vogtp <tille@handhelds.org>
10 10
11#include "listviewitemconfigentry.h" 11#include "listviewitemconfigentry.h"
12#include "listviewitemconffile.h" 12#include "listviewitemconffile.h"
13#include <qtextstream.h> 13#include <qtextstream.h>
14 14
15ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key) 15ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key)
16 : ListViewItemConf(parent) 16 : ListViewItemConf(parent)
17{ 17{
18 _fileItem = parent; 18 _fileItem = parent;
19 _file = parent->fileName(); 19 _file = parent->fileName();
20 _group = group; 20 _group = group;
21 setKey(key); 21 setKey(key);
22 _groupOrig = group;
23 _keyOrig = _key;
24 _valueOrig = _value;
22 _fileItem->unchanged(); 25 _fileItem->unchanged();
23} 26}
24 27
25ListViewItemConfigEntry::~ListViewItemConfigEntry() 28ListViewItemConfigEntry::~ListViewItemConfigEntry()
26{ 29{
27} 30}
28 31
29bool ListViewItemConfigEntry::isGroup() 32bool ListViewItemConfigEntry::isGroup()
30{ 33{
31 return _key.isEmpty(); 34 return _key.isEmpty();
32} 35}
33 36
34bool ListViewItemConfigEntry::isKey() 37bool ListViewItemConfigEntry::isKey()
35{ 38{
36 return !_key.isEmpty(); 39 return !_key.isEmpty();
37} 40}
38 41
39QString ListViewItemConfigEntry::getFile() 42QString ListViewItemConfigEntry::getFile()
40{ 43{
41 return _file; 44 return _file;
42} 45}
43 46
44void ListViewItemConfigEntry::setGroup(QString g) 47void ListViewItemConfigEntry::setGroup(QString g)
45{ 48{
46 if (g==_group) return; 49 if (g==_group) return;
47 _group = g; 50 _group = g;
48 changed(); 51 changed();
49} 52}
50 53
51QString ListViewItemConfigEntry::getGroup() 54QString ListViewItemConfigEntry::getGroup()
52{ 55{
53 return _group; 56 return _group;
54} 57}
55 58
56void ListViewItemConfigEntry::setKey(QString key) 59void ListViewItemConfigEntry::setKey(QString key)
57{ 60{
58 int pos = key.find("="); 61 int pos = key.find("=");
59 _key = key.left(pos).stripWhiteSpace(); 62 _key = key.left(pos).stripWhiteSpace();
60 _value = key.right(key.length() - pos - 1).stripWhiteSpace(); 63 _value = key.right(key.length() - pos - 1).stripWhiteSpace();
61 displayText(); 64 displayText();
62} 65}
63 66
64QString ListViewItemConfigEntry::getKey() 67QString ListViewItemConfigEntry::getKey()
65{ 68{
66 return _key; 69 return _key;
67} 70}
68 71
69QString ListViewItemConfigEntry::getValue() 72QString ListViewItemConfigEntry::getValue()
70{ 73{
71 return _value; 74 return _value;
72} 75}
73 76
74void ListViewItemConfigEntry::keyChanged(QString k) 77void ListViewItemConfigEntry::keyChanged(QString k)
75{ 78{
76 if (k==_key) return; 79 if (k==_key) return;
77 _key = k; 80 _key = k;
78 changed(); 81 changed();
79} 82}
80 83
81void ListViewItemConfigEntry::valueChanged(QString v) 84void ListViewItemConfigEntry::valueChanged(QString v)
82{ 85{
83 if (v==_value) return; 86 if (v==_value) return;
84 _value = v; 87 _value = v;
85 changed(); 88 changed();
86} 89}
87 90
88void ListViewItemConfigEntry::displayText() 91void ListViewItemConfigEntry::displayText()
89{ 92{
90 QString s; 93 QString s;
91 if (_changed) s="*"; 94 if (_changed) s="*";
92 if (isGroup()) 95 if (isGroup())
93 { 96 {
94 s += "["+_group+"]"; 97 s += "["+_group+"]";
95 _type = Group; 98 _type = Group;
96 }else{ 99 }else{
97 s += _key+" = "+_value; 100 s += _key+" = "+_value;
98 _type = Key; 101 _type = Key;
99 } 102 }
100 setText(0,s); 103 setText(0,s);
101} 104}
102 105
103void ListViewItemConfigEntry::changed() 106void ListViewItemConfigEntry::changed()
104{ 107{
105 _changed=true; 108 _changed=true;
106 displayText(); 109 displayText();
107 _fileItem->changed(); 110 _fileItem->changed();
108} 111}
109 112
113
114void ListViewItemConfigEntry::remove()
115{
116 delete this;
117}
118
110void ListViewItemConfigEntry::save(QTextStream *t) 119void ListViewItemConfigEntry::save(QTextStream *t)
111{ 120{
112 QString s; 121 QString s;
113 if (isGroup()) 122 if (isGroup())
114 { 123 {
115 s += "["+_group+"]"; 124 s += "["+_group+"]";
116 _type = Group; 125 _type = Group;
117 }else{ 126 }else{
118 s += _key+" = "+_value; 127 s += _key+" = "+_value;
119 _type = Key; 128 _type = Key;
120 } 129 }
121 s += "\n"; 130 s += "\n";
122 (*t) << s; 131 (*t) << s;
123 _changed = false; 132 _changed = false;
124 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) 133 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
125 { 134 {
126 ((ListViewItemConfigEntry*)it)->save(t); 135 ((ListViewItemConfigEntry*)it)->save(t);
127 } 136 }
137}
138
139void ListViewItemConfigEntry::revert()
140{
141 _group = _groupOrig;
142 _key = _keyOrig;
143 _value = _valueOrig;
144 _changed=false;
145 displayText();
128} \ No newline at end of file 146} \ No newline at end of file
diff --git a/noncore/apps/confedit/listviewitemconfigentry.h b/noncore/apps/confedit/listviewitemconfigentry.h
index 1ff0491..6b651a6 100644
--- a/noncore/apps/confedit/listviewitemconfigentry.h
+++ b/noncore/apps/confedit/listviewitemconfigentry.h
@@ -1,46 +1,51 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 // (c) 2002 Patrick S. Vogtp <tille@handhelds.org> 9 // (c) 2002 Patrick S. Vogtp <tille@handhelds.org>
10 10
11#ifndef LISTVIEWITEMCONFIGENTRY_H 11#ifndef LISTVIEWITEMCONFIGENTRY_H
12#define LISTVIEWITEMCONFIGENTRY_H 12#define LISTVIEWITEMCONFIGENTRY_H
13 13
14#include <qwidget.h> 14#include <qwidget.h>
15#include <qlistview.h> 15#include <qlistview.h>
16#include "listviewitemconffile.h" 16#include "listviewitemconffile.h"
17#include "listviewitemconf.h" 17#include "listviewitemconf.h"
18 18
19class QTextStream; 19class QTextStream;
20 20
21class ListViewItemConfigEntry : public ListViewItemConf { 21class ListViewItemConfigEntry : public ListViewItemConf {
22public: 22public:
23 ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key=""); 23 ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key="");
24 ~ListViewItemConfigEntry(); 24 ~ListViewItemConfigEntry();
25 bool isGroup(); 25 bool isGroup();
26 bool isKey(); 26 bool isKey();
27 QString getFile(); 27 QString getFile();
28 void setGroup(QString); 28 void setGroup(QString);
29 QString getGroup(); 29 QString getGroup();
30 void setKey(QString); 30 void setKey(QString);
31 QString getKey(); 31 QString getKey();
32 QString getValue(); 32 QString getValue();
33 void keyChanged(QString); 33 void keyChanged(QString);
34 void valueChanged(QString); 34 void valueChanged(QString);
35 virtual void displayText(); 35 virtual void displayText();
36 virtual void changed(); 36 virtual void changed();
37 virtual void remove();
37 void save(QTextStream*); 38 void save(QTextStream*);
39 virtual void revert();
38private: 40private:
39 QString _file; 41 QString _file;
40 QString _group; 42 QString _group;
41 QString _key; 43 QString _key;
42 QString _value; 44 QString _value;
45 QString _groupOrig;
46 QString _keyOrig;
47 QString _valueOrig;
43 ListViewItemConfFile *_fileItem; 48 ListViewItemConfFile *_fileItem;
44}; 49};
45 50
46#endif 51#endif
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp
index 77b91f6..17a5058 100644
--- a/noncore/apps/confedit/mainwindow.cpp
+++ b/noncore/apps/confedit/mainwindow.cpp
@@ -1,181 +1,212 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 10// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
11 11
12 12
13#include "mainwindow.h" 13#include "mainwindow.h"
14 14
15#include <qpe/qpemenubar.h> 15#include <qpe/qpemenubar.h>
16#include <qpe/qpemessagebox.h> 16#include <qpe/qpemessagebox.h>
17#include <qpe/resource.h> 17#include <qpe/resource.h>
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/qpetoolbar.h> 19#include <qpe/qpetoolbar.h>
20#include <qaction.h> 20#include <qaction.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <qpopupmenu.h> 22#include <qpopupmenu.h>
23#include <qtoolbutton.h> 23#include <qtoolbutton.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qlineedit.h> 29#include <qlineedit.h>
30 30
31#include "listviewconfdir.h" 31#include "listviewconfdir.h"
32#include "listviewitemconf.h" 32#include "listviewitemconf.h"
33#include "listviewitemconfigentry.h" 33#include "listviewitemconfigentry.h"
34 34
35 35
36MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : 36MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
37 QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0) 37 QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0)
38 { 38 {
39 setCaption( tr("Conf File Editor") ); 39 setCaption( tr("Conf File Editor") );
40 40
41 QWidget *mainWidget = new QWidget(this); 41 QWidget *mainWidget = new QWidget(this);
42 setCentralWidget( mainWidget); 42 setCentralWidget( mainWidget);
43
44 QGridLayout *mainLayout = new QGridLayout( mainWidget ); 43 QGridLayout *mainLayout = new QGridLayout( mainWidget );
45 mainLayout->setSpacing( 3 ); 44 mainLayout->setSpacing( 3 );
46 mainLayout->setMargin( 3 ); 45 mainLayout->setMargin( 3 );
47 46
48 47
48 qDebug("settingList");
49 settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); 49 settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist");
50 settingList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding));//, sizePolicy().hasHeightForWidth() ) );
50 mainLayout->addWidget( settingList, 0, 0 ); 51 mainLayout->addWidget( settingList, 0, 0 );
51 52
53 qDebug("editor");
52 editor = new EditWidget(this); 54 editor = new EditWidget(this);
55 editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum));//, sizePolicy().hasHeightForWidth() ) );
56// editor->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3));//, sizePolicy().hasHeightForWidth() ) );
53 mainLayout->addWidget( editor, 1, 0 ); 57 mainLayout->addWidget( editor, 1, 0 );
54 58
59 makeMenu();
60
61 qDebug("connect");
55 connect(settingList, SIGNAL( pressed(QListViewItem*) ), 62 connect(settingList, SIGNAL( pressed(QListViewItem*) ),
56 this, SLOT(setCurrent(QListViewItem*))); 63 this, SLOT(setCurrent(QListViewItem*)));
57 64
58 65
59 connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), 66 connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ),
60 SLOT( groupChanged(const QString&) ) ); 67 SLOT( groupChanged(const QString&) ) );
61 connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), 68 connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ),
62 SLOT( keyChanged(const QString&) ) ); 69 SLOT( keyChanged(const QString&) ) );
63 connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), 70 connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ),
64 SLOT( valueChanged(const QString&) ) ); 71 SLOT( valueChanged(const QString&) ) );
65 makeMenu(); 72// qDebug("editor->hide()");
73 // editor->hide();
74 qDebug("connect");
75 connect( settingList, SIGNAL( clicked( QListViewItem* ) ),
76 this, SLOT( stopTimer( QListViewItem* ) ) );
66} 77}
67 78
68void MainWindow::makeMenu() 79void MainWindow::makeMenu()
69{ 80{
70 81 qDebug("MainWindow::makeMenu()");
71 82
72 popupTimer = new QTimer(this); 83 popupTimer = new QTimer(this);
73 popupMenuFile = new QPopupMenu(this); 84 popupMenuFile = new QPopupMenu(this);
85 popupMenuEntry = new QPopupMenu(this);
74 86
87 qDebug("Save");
75 popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); 88 popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 );
76 popupActionSave->addTo( popupMenuFile ); 89 popupActionSave->addTo( popupMenuFile );
90 // popupActionSave->addTo( popupMenuEntry );
77 connect( popupActionSave, SIGNAL( activated() ), 91 connect( popupActionSave, SIGNAL( activated() ),
78 this , SLOT( saveConfFile() ) ); 92 this , SLOT( saveConfFile() ) );
93
94 qDebug("Revert");
79 popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); 95 popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 );
80 popupActionRevert->addTo( popupMenuFile ); 96 popupActionRevert->addTo( popupMenuFile );
97 popupActionRevert->addTo( popupMenuEntry );
81 connect( popupActionRevert, SIGNAL( activated() ), 98 connect( popupActionRevert, SIGNAL( activated() ),
82 this , SLOT( revertConfFile() ) ); 99 this , SLOT( revertConfFile() ) );
83 100
101 qDebug("Delete");
102 popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 );
103 popupActionDelete->addTo( popupMenuFile );
104 popupActionDelete->addTo( popupMenuEntry );
105 connect( popupActionDelete, SIGNAL( activated() ),
106 this , SLOT( removeConfFile() ) );
107
108 qDebug("connect");
84 connect( popupTimer, SIGNAL(timeout()), 109 connect( popupTimer, SIGNAL(timeout()),
85 this, SLOT(showPopup()) ); 110 this, SLOT(showPopup()) );
86 connect( settingList, SIGNAL( clicked( QListViewItem* ) ), 111 qDebug("connect");
87 this, SLOT( stopTimer( QListViewItem* ) ) );
88} 112}
89 113
90MainWindow::~MainWindow() 114MainWindow::~MainWindow()
91{ 115{
92} 116}
93 117
94 118
95 119
96void MainWindow::setCurrent(QListViewItem *item) 120void MainWindow::setCurrent(QListViewItem *item)
97{ 121{
98 if (!item) return; 122 if (!item) return;
99 ListViewItemConf *i = (ListViewItemConf*) item; 123 _item = (ListViewItemConf*) item;
100 if (!i) return; 124 if (!_item) return;
101 if (i->getType() == ListViewItemConf::File) 125 popupTimer->start( 750, true );
126 if (_item->getType() == ListViewItemConf::File)
102 { 127 {
103 qDebug("start timer");
104 popupTimer->start( 750, true );
105 editor->hide(); 128 editor->hide();
106 updateGeometry(); 129 updateGeometry();
107 _currentItem=0; 130 _currentItem=0;
108 _fileItem = (ListViewItemConfFile*)item; 131 _fileItem = (ListViewItemConfFile*)item;
109 return; 132 return;
110 }else editor->show(); 133 }else editor->show();
111 _fileItem = 0; 134 _fileItem = 0;
112 _currentItem = (ListViewItemConfigEntry*)item; 135 _currentItem = (ListViewItemConfigEntry*)item;
113 if (!_currentItem) return; 136 if (!_currentItem) return;
114 QString file = _currentItem->getFile(); 137 QString file = _currentItem->getFile();
115 QString group = _currentItem->getGroup(); 138 QString group = _currentItem->getGroup();
116 QString key = _currentItem->getKey(); 139 QString key = _currentItem->getKey();
117 QString val = _currentItem->getValue(); 140 QString val = _currentItem->getValue();
118 editor->TextFileName->setText(file); 141 editor->TextFileName->setText(file);
119 editor->LineEditGroup->setText(group); 142 editor->LineEditGroup->setText(group);
120 if (!key.isEmpty()) 143 if (!key.isEmpty())
121 { 144 {
122 editor->isKey(true); 145 editor->isKey(true);
123 editor->LineEditKey->setText(key); 146 editor->LineEditKey->setText(key);
124 editor->LineEditValue->setText(val); 147 editor->LineEditValue->setText(val);
125 }else{ 148 }else{
126 editor->isKey(false); 149 editor->isKey(false);
127 } 150 }
128 updateGeometry(); 151 updateGeometry();
152 editor->updateGeometry();
153 settingList->updateGeometry();
129} 154}
130 155
131 156
132void MainWindow::groupChanged(const QString &g) 157void MainWindow::groupChanged(const QString &g)
133{ 158{
134 if (!_currentItem) return; 159 if (!_currentItem) return;
135 _currentItem->setGroup(g); 160 _currentItem->setGroup(g);
136} 161}
137 162
138void MainWindow::keyChanged(const QString &k) 163void MainWindow::keyChanged(const QString &k)
139{ 164{
140 if (!_currentItem) return; 165 if (!_currentItem) return;
141 _currentItem->keyChanged(k); 166 _currentItem->keyChanged(k);
142} 167}
143 168
144void MainWindow::valueChanged(const QString &v) 169void MainWindow::valueChanged(const QString &v)
145{ 170{
146 if (!_currentItem) return; 171 if (!_currentItem) return;
147 _currentItem->valueChanged(v); 172 _currentItem->valueChanged(v);
148} 173}
149 174
150 175
151void MainWindow::stopTimer( QListViewItem* ) 176void MainWindow::stopTimer( QListViewItem* )
152{ 177{
153 qDebug("stopTimer");
154 popupTimer->stop(); 178 popupTimer->stop();
155} 179}
156 180
157void MainWindow::saveConfFile() 181void MainWindow::saveConfFile()
158{ 182{
159 if (!_fileItem) return; 183 if (!_fileItem) return;
160 _fileItem->save(); 184 _fileItem->save();
161} 185}
162 186
163void MainWindow::revertConfFile() 187void MainWindow::revertConfFile()
164{ 188{
165 if (!_fileItem) return; 189 if (!_item) return;
166 _fileItem->revert(); 190 _item->revert();
167} 191}
168 192
193void MainWindow::removeConfFile()
194{
195 if (!_item) return;
196 _item->remove();
197}
169void MainWindow::showPopup() 198void MainWindow::showPopup()
170{ 199{
171 qDebug("showPopup"); 200qDebug("showPopup");
201 if (!_item) return;
202 popupActionRevert->setEnabled(_item->revertable());
203 popupActionSave->setEnabled(_item->isChanged());
172 if (_fileItem) 204 if (_fileItem)
173 { 205 {
174 popupActionSave->setEnabled(_fileItem->isChanged()); 206 popupActionSave->setEnabled(_fileItem->isChanged());
175 popupActionRevert->setEnabled(_fileItem->revertable());
176 popupMenuFile->popup( QCursor::pos() ); 207 popupMenuFile->popup( QCursor::pos() );
177 }else if(_currentItem->isChanged()) 208 }else if(_currentItem)
178 { 209 {
179 210 popupMenuEntry->popup( QCursor::pos() );
180 } 211 }
181} 212}
diff --git a/noncore/apps/confedit/mainwindow.h b/noncore/apps/confedit/mainwindow.h
index e0dc0b0..886b829 100644
--- a/noncore/apps/confedit/mainwindow.h
+++ b/noncore/apps/confedit/mainwindow.h
@@ -1,64 +1,66 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 10// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
11 11
12#ifndef MAINWINDOW_H 12#ifndef MAINWINDOW_H
13#define MAINWINDOW_H 13#define MAINWINDOW_H
14 14
15#include <qmainwindow.h> 15#include <qmainwindow.h>
16#include <qaction.h> 16#include <qaction.h>
17#include <qtimer.h> 17#include <qtimer.h>
18#include <qpopupmenu.h> 18#include <qpopupmenu.h>
19#include "editwidget.h" 19#include "editwidget.h"
20 20
21class QPEToolBar; 21class QPEToolBar;
22class ListViewItemConfFile; 22class ListViewItemConfFile;
23class ListViewConfDir; 23class ListViewConfDir;
24 24class ListViewItemConf;
25 25
26class MainWindow : public QMainWindow 26class MainWindow : public QMainWindow
27{ 27{
28 Q_OBJECT 28 Q_OBJECT
29 29
30 30
31public: 31public:
32 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 32 MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
33 ~MainWindow(); 33 ~MainWindow();
34 34
35 35
36public slots: 36public slots:
37 void setCurrent(QListViewItem*); 37 void setCurrent(QListViewItem*);
38 void groupChanged(const QString&); 38 void groupChanged(const QString&);
39 void keyChanged(const QString&); 39 void keyChanged(const QString&);
40 void valueChanged(const QString&); 40 void valueChanged(const QString&);
41 void showPopup(); 41 void showPopup();
42 void stopTimer( QListViewItem* ); 42 void stopTimer( QListViewItem* );
43 void saveConfFile(); 43 void saveConfFile();
44 void revertConfFile(); 44 void revertConfFile();
45 void removeConfFile();
45 46
46private: 47private:
47 ListViewConfDir *settingList; 48 ListViewConfDir *settingList;
48 EditWidget *editor; 49 EditWidget *editor;
50 ListViewItemConf *_item;
49 ListViewItemConfigEntry *_currentItem; 51 ListViewItemConfigEntry *_currentItem;
50 ListViewItemConfFile *_fileItem; 52 ListViewItemConfFile *_fileItem;
51 QTimer *popupTimer; 53 QTimer *popupTimer;
52 QPopupMenu *popupMenuFile; 54 QPopupMenu *popupMenuFile;
53 QPopupMenu *popupMenuEntry; 55 QPopupMenu *popupMenuEntry;
54 QAction *popupActionSave; 56 QAction *popupActionSave;
55 QAction *popupActionRevert; 57 QAction *popupActionRevert;
56 QAction *popupActionDelete; 58 QAction *popupActionDelete;
57 QAction *popupActionNew; 59 QAction *popupActionNew;
58 //QAction *popupAction; 60 //QAction *popupAction;
59 //QAction *popupAction; 61 //QAction *popupAction;
60 62
61 void makeMenu(); 63 void makeMenu();
62}; 64};
63 65
64#endif 66#endif