Diffstat (limited to 'noncore/apps/confedit/listviewitemconffile.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 5457384..a8fd770 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -12,77 +12,88 @@ | |||
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 | ||
19 | ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) | 19 | ListViewItemConfFile::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 | _changed = false; | ||
25 | displayText(); | 24 | displayText(); |
26 | } | 25 | } |
27 | 26 | ||
28 | ListViewItemConfFile::~ListViewItemConfFile() | 27 | ListViewItemConfFile::~ListViewItemConfFile() |
29 | { | 28 | { |
30 | } | 29 | } |
31 | 30 | ||
32 | 31 | ||
33 | void ListViewItemConfFile::displayText() | 32 | void ListViewItemConfFile::displayText() |
34 | { | 33 | { |
35 | setText(0,(_changed?"*":"*")+confFileInfo->fileName()); | 34 | setText(0,(_changed?"*":"")+confFileInfo->fileName()); |
36 | } | 35 | } |
37 | 36 | ||
38 | QString ListViewItemConfFile::fileName() | 37 | QString ListViewItemConfFile::fileName() |
39 | { | 38 | { |
40 | return confFileInfo->fileName(); | 39 | return confFileInfo->fileName(); |
41 | } | 40 | } |
42 | 41 | ||
43 | void ListViewItemConfFile::parseFile() | 42 | void ListViewItemConfFile::parseFile() |
44 | { | 43 | { |
45 | qDebug( confFileInfo->absFilePath() ); | ||
46 | QFile confFile(confFileInfo->absFilePath()); | 44 | QFile confFile(confFileInfo->absFilePath()); |
47 | qDebug( confFileInfo->absFilePath() ); | ||
48 | // QString fileName = confFileInfo->fileName(); | ||
49 | if(! confFile.open(IO_ReadOnly)) | 45 | if(! confFile.open(IO_ReadOnly)) |
50 | 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); |
51 | QTextStream t( &confFile ); | 47 | QTextStream t( &confFile ); |
52 | QString s; | 48 | QString s; |
53 | QString group; | 49 | QString group; |
54 | ListViewItemConfigEntry *groupItem; | 50 | ListViewItemConfigEntry *groupItem; |
55 | ListViewItemConfigEntry *item; | 51 | ListViewItemConfigEntry *item; |
56 | while ( !t.atEnd() ) | 52 | while ( !t.atEnd() ) |
57 | { | 53 | { |
58 | s = t.readLine().stripWhiteSpace(); | 54 | s = t.readLine().stripWhiteSpace(); |
59 | //qDebug( "line: >%s<\n", s.latin1() ); | 55 | //qDebug( "line: >%s<\n", s.latin1() ); |
60 | if (s.contains("<?xml")) | 56 | if (s.contains("<?xml")) |
61 | { | 57 | { |
62 | _valid = false; | 58 | _valid = false; |
63 | break; | 59 | break; |
64 | }else | 60 | }else |
65 | if ( s[0] == '[' && s[s.length()-1] == ']' ) | 61 | if ( s[0] == '[' && s[s.length()-1] == ']' ) |
66 | { | 62 | { |
67 | qDebug("got group"+s); | 63 | // qDebug("got group"+s); |
68 | group = s.mid(1,s.length()-2); | 64 | group = s.mid(1,s.length()-2); |
69 | groupItem = new ListViewItemConfigEntry(this, group ); | 65 | groupItem = new ListViewItemConfigEntry(this, group ); |
70 | insertItem( groupItem ); | 66 | insertItem( groupItem ); |
71 | } else | 67 | } else |
72 | if ( int pos = s.find('=') ) | 68 | if ( int pos = s.find('=') ) |
73 | { | 69 | { |
74 | // qDebug("got key"+s); | 70 | // qDebug("got key"+s); |
75 | item = new ListViewItemConfigEntry(this, group, s ); | 71 | item = new ListViewItemConfigEntry(this, group, s ); |
76 | groupItem->insertItem( item ); | 72 | groupItem->insertItem( item ); |
77 | } | 73 | } |
78 | } | 74 | } |
79 | confFile.close(); | 75 | confFile.close(); |
80 | setExpandable( _valid ); | 76 | setExpandable( _valid ); |
81 | } | 77 | } |
82 | 78 | ||
83 | void ListViewItemConfFile::save() | 79 | void ListViewItemConfFile::save() |
84 | { | 80 | { |
85 | qDebug("ListViewItemConfFile::save()"); | 81 | if (!_changed) return; |
82 | QString backup = confFileInfo->absFilePath()+"~"; | ||
83 | qDebug("make backup to "+backup); | ||
84 | QFile conf(confFileInfo->absFilePath()); | ||
85 | QFile back(backup); | ||
86 | |||
87 | if (!conf.open(IO_ReadOnly)) return; | ||
88 | if (!back.open(IO_WriteOnly)) return; | ||
89 | |||
90 | #define SIZE 124 | ||
91 | char buf[SIZE]; | ||
92 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); | ||
93 | conf.close(); | ||
94 | back.close(); | ||
95 | |||
96 | |||
86 | qDebug("no saveing yet..."); | 97 | qDebug("no saveing yet..."); |
87 | unchanged(); | 98 | unchanged(); |
88 | } | 99 | } |