-rw-r--r-- | noncore/apps/confedit/listviewconfdir.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 25 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.h | 1 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 31 |
4 files changed, 21 insertions, 38 deletions
diff --git a/noncore/apps/confedit/listviewconfdir.cpp b/noncore/apps/confedit/listviewconfdir.cpp index b76e425..f466f06 100644 --- a/noncore/apps/confedit/listviewconfdir.cpp +++ b/noncore/apps/confedit/listviewconfdir.cpp | |||
@@ -15,39 +15,39 @@ | |||
15 | #include "listviewitemconffile.h" | 15 | #include "listviewitemconffile.h" |
16 | 16 | ||
17 | ListViewConfDir::ListViewConfDir(QString settingsPath, QWidget *parent, const char *name ) | 17 | ListViewConfDir::ListViewConfDir(QString settingsPath, QWidget *parent, const char *name ) |
18 | : QListView(parent,name), confDir(settingsPath) | 18 | : QListView(parent,name), confDir(settingsPath) |
19 | { | 19 | { |
20 | 20 | ||
21 | setRootIsDecorated( true ); | 21 | setRootIsDecorated( true ); |
22 | addColumn(tr("Files")); | 22 | addColumn(tr("Files")); |
23 | 23 | ||
24 | if (!confDir.isReadable()) | 24 | if (!confDir.isReadable()) |
25 | QMessageBox::critical(this,tr("Could not open"),tr("The directory ")+settingsPath+tr(" could not be opened."),1,0); | 25 | QMessageBox::critical(this,tr("Could not open"),tr("The directory ")+settingsPath+tr(" could not be opened."),1,0); |
26 | readConfFiles(); | 26 | readConfFiles(); |
27 | } | 27 | } |
28 | 28 | ||
29 | 29 | ||
30 | ListViewConfDir::~ListViewConfDir() | 30 | ListViewConfDir::~ListViewConfDir() |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | void ListViewConfDir::readConfFiles() | 34 | void ListViewConfDir::readConfFiles() |
35 | { | 35 | { |
36 | 36 | ||
37 | confDir.setFilter( QDir::Files | QDir::NoSymLinks ); | 37 | confDir.setFilter( QDir::Files | QDir::NoSymLinks ); |
38 | confDir.setSorting( QDir::Name ); | 38 | confDir.setSorting( QDir::Name ); |
39 | 39 | confDir.setNameFilter("*.conf"); | |
40 | const QFileInfoList *list = confDir.entryInfoList(); | 40 | const QFileInfoList *list = confDir.entryInfoList(); |
41 | QFileInfoListIterator it( *list ); | 41 | QFileInfoListIterator it( *list ); |
42 | QFileInfo *fi; | 42 | QFileInfo *fi; |
43 | 43 | ||
44 | ListViewItemConfFile *fileEntry; | 44 | ListViewItemConfFile *fileEntry; |
45 | 45 | ||
46 | while ( (fi=it.current()) ) | 46 | while ( (fi=it.current()) ) |
47 | { | 47 | { |
48 | qDebug( "opening: >%s<", fi->fileName().data() ); | 48 | qDebug( "opening: >%s<", fi->fileName().data() ); |
49 | fileEntry = new ListViewItemConfFile( fi, this ); | 49 | fileEntry = new ListViewItemConfFile( fi, this ); |
50 | 50 | ||
51 | ++it; | 51 | ++it; |
52 | } | 52 | } |
53 | } \ No newline at end of file | 53 | } \ No newline at end of file |
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 | |||
@@ -1,88 +1,99 @@ | |||
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 | ||
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 | } |
diff --git a/noncore/apps/confedit/listviewitemconffile.h b/noncore/apps/confedit/listviewitemconffile.h index 9208918..d89b19c 100644 --- a/noncore/apps/confedit/listviewitemconffile.h +++ b/noncore/apps/confedit/listviewitemconffile.h | |||
@@ -4,33 +4,32 @@ | |||
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 | ||
21 | class ListViewItemConfFile : public ListViewItemConf { | 21 | class ListViewItemConfFile : public ListViewItemConf { |
22 | public: | 22 | public: |
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(); | 27 | virtual void displayText(); |
28 | /** No descriptions */ | ||
29 | void save(); | 28 | void save(); |
30 | protected: | 29 | protected: |
31 | private: | 30 | private: |
32 | bool _valid; | 31 | bool _valid; |
33 | QFileInfo *confFileInfo; | 32 | QFileInfo *confFileInfo; |
34 | }; | 33 | }; |
35 | 34 | ||
36 | #endif | 35 | #endif |
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 5eeeb90..30dfdf7 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp | |||
@@ -65,63 +65,61 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
65 | 65 | ||
66 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), | 66 | connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), |
67 | SLOT( groupChanged(const QString&) ) ); | 67 | SLOT( groupChanged(const QString&) ) ); |
68 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), | 68 | connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), |
69 | SLOT( keyChanged(const QString&) ) ); | 69 | SLOT( keyChanged(const QString&) ) ); |
70 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), | 70 | connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), |
71 | SLOT( valueChanged(const QString&) ) ); | 71 | SLOT( valueChanged(const QString&) ) ); |
72 | makeMenu(); | 72 | makeMenu(); |
73 | } | 73 | } |
74 | 74 | ||
75 | void MainWindow::makeMenu() | 75 | void MainWindow::makeMenu() |
76 | { | 76 | { |
77 | 77 | ||
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | MainWindow::~MainWindow() | 81 | MainWindow::~MainWindow() |
82 | { | 82 | { |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | 86 | ||
87 | void MainWindow::setCurrent(QListViewItem *item) | 87 | void MainWindow::setCurrent(QListViewItem *item) |
88 | { | 88 | { |
89 | qDebug("MainWindow::setCurrent("); | ||
90 | if (!item) return; | 89 | if (!item) return; |
91 | qDebug("cast ListViewItemConf"); | ||
92 | ListViewItemConf *i = (ListViewItemConf*) item; | 90 | ListViewItemConf *i = (ListViewItemConf*) item; |
93 | if (!i) return; | 91 | if (!i) return; |
94 | if (i->getType() == ListViewItemConf::File) | 92 | if (i->getType() == ListViewItemConf::File) |
95 | { | 93 | { |
94 | qDebug("start timer"); | ||
96 | popupTimer->start( 750, true ); | 95 | popupTimer->start( 750, true ); |
97 | editor->hide(); | 96 | editor->hide(); |
98 | updateGeometry(); | 97 | updateGeometry(); |
99 | _currentItem=0; | 98 | _currentItem=0; |
100 | _fileItem = (ListViewItemConfFile*)item; | 99 | _fileItem = (ListViewItemConfFile*)item; |
101 | return; | 100 | return; |
102 | }else editor->show(); | 101 | }else editor->show(); |
103 | qDebug("cast ListViewItemConfigEntry"); | ||
104 | _fileItem = 0; | 102 | _fileItem = 0; |
105 | _currentItem = (ListViewItemConfigEntry*)item; | 103 | _currentItem = (ListViewItemConfigEntry*)item; |
106 | if (!_currentItem) return; | 104 | if (!_currentItem) return; |
107 | QString file = _currentItem->getFile(); | 105 | QString file = _currentItem->getFile(); |
108 | QString group = _currentItem->getGroup(); | 106 | QString group = _currentItem->getGroup(); |
109 | QString key = _currentItem->getKey(); | 107 | QString key = _currentItem->getKey(); |
110 | QString val = _currentItem->getValue(); | 108 | QString val = _currentItem->getValue(); |
111 | editor->TextFileName->setText(file); | 109 | editor->TextFileName->setText(file); |
112 | editor->LineEditGroup->setText(group); | 110 | editor->LineEditGroup->setText(group); |
113 | if (!key.isEmpty()) | 111 | if (!key.isEmpty()) |
114 | { | 112 | { |
115 | editor->isKey(true); | 113 | editor->isKey(true); |
116 | editor->LineEditKey->setText(key); | 114 | editor->LineEditKey->setText(key); |
117 | editor->LineEditValue->setText(val); | 115 | editor->LineEditValue->setText(val); |
118 | }else{ | 116 | }else{ |
119 | editor->isKey(false); | 117 | editor->isKey(false); |
120 | } | 118 | } |
121 | updateGeometry(); | 119 | updateGeometry(); |
122 | } | 120 | } |
123 | 121 | ||
124 | 122 | ||
125 | void MainWindow::groupChanged(const QString &g) | 123 | void MainWindow::groupChanged(const QString &g) |
126 | { | 124 | { |
127 | if (!_currentItem) return; | 125 | if (!_currentItem) return; |
@@ -144,52 +142,27 @@ void MainWindow::valueChanged(const QString &v) | |||
144 | void MainWindow::stopTimer( QListViewItem* ) | 142 | void MainWindow::stopTimer( QListViewItem* ) |
145 | { | 143 | { |
146 | qDebug("stopTimer"); | 144 | qDebug("stopTimer"); |
147 | popupTimer->stop(); | 145 | popupTimer->stop(); |
148 | } | 146 | } |
149 | 147 | ||
150 | void MainWindow::saveConfFile() | 148 | void MainWindow::saveConfFile() |
151 | { | 149 | { |
152 | if (!_fileItem) return; | 150 | if (!_fileItem) return; |
153 | _fileItem->save(); | 151 | _fileItem->save(); |
154 | } | 152 | } |
155 | 153 | ||
156 | void MainWindow::showPopup() | 154 | void MainWindow::showPopup() |
157 | { | 155 | { |
158 | qDebug("showPopup"); | 156 | qDebug("showPopup"); |
159 | if (!_fileItem) return; | 157 | if (!_fileItem) return; |
160 | popupMenu->clear(); | 158 | popupMenu->clear(); |
161 | 159 | ||
162 | QAction *popupAction; | 160 | QAction *popupAction; |
163 | popupAction = new QAction( tr("Save"),QString::null, 0, this, 0 ); | 161 | popupAction = new QAction( tr("Save"),QString::null, 0, this, 0 ); |
164 | popupAction->addTo( popupMenu ); | 162 | popupAction->addTo( popupMenu ); |
165 | connect( popupAction, SIGNAL( activated() ), | 163 | connect( popupAction, SIGNAL( activated() ), |
166 | this , SLOT( saveConfFile() ) ); | 164 | this , SLOT( saveConfFile() ) ); |
167 | 165 | ||
168 | // if ( !activePackage->installed() ) | 166 | |
169 | // { | ||
170 | // popupMenu->insertItem( tr("Install to"), destsMenu ); | ||
171 | // QStringList dests = settings->getDestinationNames(); | ||
172 | // QString ad = settings->getDestinationName(); | ||
173 | // for (uint i = 0; i < dests.count(); i++ ) | ||
174 | // { | ||
175 | // popupAction = new QAction( dests[i], QString::null, 0, this, 0 ); | ||
176 | // popupAction->addTo( destsMenu ); | ||
177 | // if ( dests[i] == ad && activePackage->toInstall() ) | ||
178 | // { | ||
179 | // popupAction->setToggleAction( true ); | ||
180 | // popupAction->setOn(true); | ||
181 | // }; | ||
182 | // } | ||
183 | // connect( destsMenu, SIGNAL( activated( int ) ), | ||
184 | // this, SLOT( changePackageDest( int ) ) ); | ||
185 | // }else{ | ||
186 | // popupAction = new QAction( tr("Remove"),QString::null, 0, this, 0 ); | ||
187 | // popupAction->addTo( popupMenu ); | ||
188 | // connect( popupAction, SIGNAL( activated() ), | ||
189 | // this , SLOT( toggleProcess() ) ); | ||
190 | // popupAction = new QAction( tr("Reinstall"),QString::null, 0, this, 0 ); | ||
191 | // popupAction->addTo( popupMenu ); | ||
192 | // popupAction->setEnabled( false ); | ||
193 | // } | ||
194 | popupMenu->popup( QCursor::pos() ); | 167 | popupMenu->popup( QCursor::pos() ); |
195 | } | 168 | } |