Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 2958cf5..a7d6b00 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -1,133 +1,138 @@ | |||
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 "listviewitemconfigentry.h" | 12 | #include "listviewitemconfigentry.h" |
13 | 13 | ||
14 | /* OPIE */ | 14 | /* OPIE */ |
15 | #include <opie2/odebug.h> | 15 | #include <opie2/odebug.h> |
16 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
17 | 17 | ||
18 | /* QT */ | 18 | /* QT */ |
19 | #include <qmessagebox.h> | 19 | #include <qmessagebox.h> |
20 | #include <qtextstream.h> | 20 | #include <qtextstream.h> |
21 | 21 | ||
22 | #define tr QObject::tr | 22 | #define tr QObject::tr |
23 | 23 | ||
24 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) | 24 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) |
25 | : ListViewItemConf(parent), _valid(false) | 25 | : ListViewItemConf(parent), _valid(false) |
26 | { | 26 | { |
27 | confFileInfo = file; | 27 | confFileInfo = file; |
28 | // parseFile(); | 28 | // parseFile(); |
29 | displayText(); | 29 | displayText(); |
30 | } | 30 | } |
31 | 31 | ||
32 | ListViewItemConfFile::~ListViewItemConfFile() | 32 | ListViewItemConfFile::~ListViewItemConfFile() |
33 | { | 33 | { |
34 | } | 34 | } |
35 | 35 | ||
36 | 36 | ||
37 | void ListViewItemConfFile::displayText() | 37 | void ListViewItemConfFile::displayText() |
38 | { | 38 | { |
39 | setText(0,(_changed?"*":"")+confFileInfo->fileName()); | 39 | setText(0,(_changed?"*":"")+confFileInfo->fileName()); |
40 | } | 40 | } |
41 | 41 | ||
42 | QString ListViewItemConfFile::fileName() | 42 | QString ListViewItemConfFile::fileName() |
43 | { | 43 | { |
44 | return confFileInfo->fileName(); | 44 | return confFileInfo->fileName(); |
45 | } | 45 | } |
46 | 46 | ||
47 | void ListViewItemConfFile::parseFile() | 47 | void ListViewItemConfFile::parseFile() |
48 | { | 48 | { |
49 | //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; | 49 | //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; |
50 | QFile confFile(confFileInfo->absFilePath()); | 50 | QFile confFile(confFileInfo->absFilePath()); |
51 | if(! confFile.open(IO_ReadOnly)) | 51 | if(! confFile.open(IO_ReadOnly)) |
52 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); | 52 | QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); |
53 | QTextStream t( &confFile ); | 53 | |
54 | QString s; | 54 | QTextStream t( &confFile ); |
55 | QString s; | ||
55 | QString group; | 56 | QString group; |
56 | ListViewItemConfigEntry *groupItem; | 57 | ListViewItemConfigEntry *groupItem = 0; |
57 | ListViewItemConfigEntry *item; | 58 | ListViewItemConfigEntry *item; |
58 | while ( !t.atEnd() ) | 59 | while ( !t.atEnd() ) |
59 | { | 60 | { |
60 | s = t.readLine().stripWhiteSpace(); | 61 | s = t.readLine().stripWhiteSpace(); |
61 | //odebug << "line: >" << s.latin1() << "<\n" << oendl; | 62 | //odebug << "line: >" << s.latin1() << "<\n" << oendl; |
62 | if (s.contains("<?xml")) | 63 | if (s.contains("<?xml")) |
63 | { | 64 | { |
64 | _valid = false; | 65 | _valid = false; |
65 | break; | 66 | break; |
66 | }else | 67 | } |
67 | if ( s[0] == '[' && s[s.length()-1] == ']' ) | 68 | else if ( s[0] == '[' && s[s.length()-1] == ']' ) |
68 | { | 69 | { |
69 | // odebug << "got group"+s << oendl; | 70 | //odebug << "got group"+s << oendl; |
70 | group = s.mid(1,s.length()-2); | 71 | group = s.mid(1,s.length()-2); |
71 | if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); | 72 | if (!groupItem) |
73 | groupItem = new ListViewItemConfigEntry(this, tr("no group") ); | ||
74 | |||
72 | groupItem = new ListViewItemConfigEntry(this, group ); | 75 | groupItem = new ListViewItemConfigEntry(this, group ); |
73 | insertItem( groupItem ); | 76 | insertItem( groupItem ); |
74 | } else | 77 | } |
75 | if ( int pos = s.find('=') ) | 78 | else if ( int pos = s.find('=') ) |
76 | { | 79 | { |
77 | // odebug << "got key"+s << oendl; | 80 | //odebug << "got key"+s << oendl; |
78 | if (!groupItem) odebug << "PANIK NO GROUP! >" << group.latin1() << "<" << oendl; | 81 | if (!groupItem) |
79 | item = new ListViewItemConfigEntry(this, group, s ); | 82 | odebug << "PANIC! no group >" << group.latin1() << "<" << oendl; |
83 | |||
84 | item = new ListViewItemConfigEntry(this, group, s ); | ||
80 | groupItem->insertItem( item ); | 85 | groupItem->insertItem( item ); |
81 | } | 86 | } |
82 | } | 87 | } |
83 | confFile.close(); | 88 | confFile.close(); |
84 | setExpandable( _valid ); | 89 | setExpandable( _valid ); |
85 | //odebug << "ListViewItemConfFile::parseFile END" << oendl; | 90 | //odebug << "ListViewItemConfFile::parseFile END" << oendl; |
86 | } | 91 | } |
87 | 92 | ||
88 | 93 | ||
89 | void ListViewItemConfFile::remove() | 94 | void ListViewItemConfFile::remove() |
90 | { | 95 | { |
91 | QFile::remove(confFileInfo->absFilePath()); | 96 | QFile::remove(confFileInfo->absFilePath()); |
92 | QFile::remove(backupFileName()); | 97 | QFile::remove(backupFileName()); |
93 | delete this; | 98 | delete this; |
94 | } | 99 | } |
95 | 100 | ||
96 | void ListViewItemConfFile::revert() | 101 | void ListViewItemConfFile::revert() |
97 | { | 102 | { |
98 | if (!_changed) | 103 | if (!_changed) |
99 | { | 104 | { |
100 | // read the backup file | 105 | // read the backup file |
101 | QFile conf(confFileInfo->absFilePath()); | 106 | QFile conf(confFileInfo->absFilePath()); |
102 | QFile back(backupFileName()); | 107 | QFile back(backupFileName()); |
103 | 108 | ||
104 | if (!back.open(IO_ReadOnly)) return; | 109 | if (!back.open(IO_ReadOnly)) return; |
105 | if (!conf.open(IO_WriteOnly)) return; | 110 | if (!conf.open(IO_WriteOnly)) return; |
106 | 111 | ||
107 | #define SIZE 124 | 112 | #define SIZE 124 |
108 | char buf[SIZE]; | 113 | char buf[SIZE]; |
109 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); | 114 | while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); |
110 | conf.close(); | 115 | conf.close(); |
111 | back.close(); | 116 | back.close(); |
112 | } | 117 | } |
113 | parseFile(); | 118 | parseFile(); |
114 | expand(); | 119 | expand(); |
115 | } | 120 | } |
116 | 121 | ||
117 | void ListViewItemConfFile::save() | 122 | void ListViewItemConfFile::save() |
118 | { | 123 | { |
119 | if (!_changed) return; | 124 | if (!_changed) return; |
120 | QFile conf(confFileInfo->absFilePath()); | 125 | QFile conf(confFileInfo->absFilePath()); |
121 | QFile back(backupFileName()); | 126 | QFile back(backupFileName()); |
122 | 127 | ||
123 | if (!conf.open(IO_ReadOnly)) return; | 128 | if (!conf.open(IO_ReadOnly)) return; |
124 | if (!back.open(IO_WriteOnly)) return; | 129 | if (!back.open(IO_WriteOnly)) return; |
125 | 130 | ||
126 | char buf[SIZE]; | 131 | char buf[SIZE]; |
127 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); | 132 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); |
128 | conf.close(); | 133 | conf.close(); |
129 | back.close(); | 134 | back.close(); |
130 | 135 | ||
131 | 136 | ||
132 | if (!conf.open(IO_WriteOnly)) return; | 137 | if (!conf.open(IO_WriteOnly)) return; |
133 | QTextStream *t = new QTextStream( &conf ); | 138 | QTextStream *t = new QTextStream( &conf ); |