-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.cpp | 21 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.h | 3 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 24 |
4 files changed, 44 insertions, 13 deletions
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index a8fd770..858726d 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp | |||
@@ -63,37 +63,44 @@ void ListViewItemConfFile::parseFile() | |||
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 | setExpandable( _valid ); | 76 | setExpandable( _valid ); |
77 | } | 77 | } |
78 | 78 | ||
79 | void ListViewItemConfFile::save() | 79 | void ListViewItemConfFile::save() |
80 | { | 80 | { |
81 | if (!_changed) return; | 81 | if (!_changed) return; |
82 | QString backup = confFileInfo->absFilePath()+"~"; | 82 | QString backup = confFileInfo->absFilePath()+"~"; |
83 | qDebug("make backup to "+backup); | 83 | qDebug("make backup to "+backup); |
84 | QFile conf(confFileInfo->absFilePath()); | 84 | QFile conf(confFileInfo->absFilePath()); |
85 | QFile back(backup); | 85 | QFile back(backup); |
86 | 86 | ||
87 | if (!conf.open(IO_ReadOnly)) return; | 87 | if (!conf.open(IO_ReadOnly)) return; |
88 | if (!back.open(IO_WriteOnly)) return; | 88 | if (!back.open(IO_WriteOnly)) return; |
89 | 89 | ||
90 | #define SIZE 124 | 90 | #define SIZE 124 |
91 | char buf[SIZE]; | 91 | char buf[SIZE]; |
92 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); | 92 | while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); |
93 | conf.close(); | 93 | conf.close(); |
94 | back.close(); | 94 | back.close(); |
95 | |||
96 | 95 | ||
96 | |||
97 | if (!conf.open(IO_WriteOnly)) return; | ||
98 | QTextStream *t = new QTextStream( &conf ); | ||
99 | for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) | ||
100 | { | ||
101 | ((ListViewItemConfigEntry*)it)->save(t); | ||
102 | } | ||
103 | conf.close(); | ||
97 | qDebug("no saveing yet..."); | 104 | qDebug("no saveing yet..."); |
98 | unchanged(); | 105 | unchanged(); |
99 | } | 106 | } |
diff --git a/noncore/apps/confedit/listviewitemconfigentry.cpp b/noncore/apps/confedit/listviewitemconfigentry.cpp index 16be46e..77ce17d 100644 --- a/noncore/apps/confedit/listviewitemconfigentry.cpp +++ b/noncore/apps/confedit/listviewitemconfigentry.cpp | |||
@@ -1,44 +1,45 @@ | |||
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 | 14 | ||
14 | ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key) | 15 | ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key) |
15 | : ListViewItemConf(parent) | 16 | : ListViewItemConf(parent) |
16 | { | 17 | { |
17 | _fileItem = parent; | 18 | _fileItem = parent; |
18 | _file = parent->fileName(); | 19 | _file = parent->fileName(); |
19 | _group = group; | 20 | _group = group; |
20 | setKey(key); | 21 | setKey(key); |
21 | _fileItem->unchanged(); | 22 | _fileItem->unchanged(); |
22 | } | 23 | } |
23 | 24 | ||
24 | ListViewItemConfigEntry::~ListViewItemConfigEntry() | 25 | ListViewItemConfigEntry::~ListViewItemConfigEntry() |
25 | { | 26 | { |
26 | } | 27 | } |
27 | 28 | ||
28 | bool ListViewItemConfigEntry::isGroup() | 29 | bool ListViewItemConfigEntry::isGroup() |
29 | { | 30 | { |
30 | return _key.isEmpty(); | 31 | return _key.isEmpty(); |
31 | } | 32 | } |
32 | 33 | ||
33 | bool ListViewItemConfigEntry::isKey() | 34 | bool ListViewItemConfigEntry::isKey() |
34 | { | 35 | { |
35 | return !_key.isEmpty(); | 36 | return !_key.isEmpty(); |
36 | } | 37 | } |
37 | 38 | ||
38 | QString ListViewItemConfigEntry::getFile() | 39 | QString ListViewItemConfigEntry::getFile() |
39 | { | 40 | { |
40 | return _file; | 41 | return _file; |
41 | } | 42 | } |
42 | 43 | ||
43 | void ListViewItemConfigEntry::setGroup(QString g) | 44 | void ListViewItemConfigEntry::setGroup(QString g) |
44 | { | 45 | { |
@@ -75,33 +76,53 @@ void ListViewItemConfigEntry::keyChanged(QString k) | |||
75 | if (k==_key) return; | 76 | if (k==_key) return; |
76 | _key = k; | 77 | _key = k; |
77 | changed(); | 78 | changed(); |
78 | } | 79 | } |
79 | 80 | ||
80 | void ListViewItemConfigEntry::valueChanged(QString v) | 81 | void ListViewItemConfigEntry::valueChanged(QString v) |
81 | { | 82 | { |
82 | if (v==_value) return; | 83 | if (v==_value) return; |
83 | _value = v; | 84 | _value = v; |
84 | changed(); | 85 | changed(); |
85 | } | 86 | } |
86 | 87 | ||
87 | void ListViewItemConfigEntry::displayText() | 88 | void ListViewItemConfigEntry::displayText() |
88 | { | 89 | { |
89 | QString s; | 90 | QString s; |
90 | if (_changed) s="*"; | 91 | if (_changed) s="*"; |
91 | if (isGroup()) | 92 | if (isGroup()) |
92 | { | 93 | { |
93 | s += "["+_group+"]"; | 94 | s += "["+_group+"]"; |
94 | _type = Group; | 95 | _type = Group; |
95 | }else{ | 96 | }else{ |
96 | s += _key+" = "+_value; | 97 | s += _key+" = "+_value; |
97 | _type = Key; | 98 | _type = Key; |
98 | } | 99 | } |
99 | setText(0,s); | 100 | setText(0,s); |
100 | } | 101 | } |
101 | 102 | ||
102 | void ListViewItemConfigEntry::changed() | 103 | void ListViewItemConfigEntry::changed() |
103 | { | 104 | { |
104 | _changed=true; | 105 | _changed=true; |
105 | displayText(); | 106 | displayText(); |
106 | _fileItem->changed(); | 107 | _fileItem->changed(); |
108 | } | ||
109 | |||
110 | void ListViewItemConfigEntry::save(QTextStream *t) | ||
111 | { | ||
112 | QString s; | ||
113 | if (isGroup()) | ||
114 | { | ||
115 | s += "["+_group+"]"; | ||
116 | _type = Group; | ||
117 | }else{ | ||
118 | s += _key+" = "+_value; | ||
119 | _type = Key; | ||
120 | } | ||
121 | s += "\n"; | ||
122 | (*t) << s; | ||
123 | _changed = false; | ||
124 | for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) | ||
125 | { | ||
126 | ((ListViewItemConfigEntry*)it)->save(t); | ||
127 | } | ||
107 | } \ No newline at end of file | 128 | } \ No newline at end of file |
diff --git a/noncore/apps/confedit/listviewitemconfigentry.h b/noncore/apps/confedit/listviewitemconfigentry.h index d2b331f..1ff0491 100644 --- a/noncore/apps/confedit/listviewitemconfigentry.h +++ b/noncore/apps/confedit/listviewitemconfigentry.h | |||
@@ -1,43 +1,46 @@ | |||
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 | ||
19 | class QTextStream; | ||
20 | |||
19 | class ListViewItemConfigEntry : public ListViewItemConf { | 21 | class ListViewItemConfigEntry : public ListViewItemConf { |
20 | public: | 22 | public: |
21 | ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key=""); | 23 | ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key=""); |
22 | ~ListViewItemConfigEntry(); | 24 | ~ListViewItemConfigEntry(); |
23 | bool isGroup(); | 25 | bool isGroup(); |
24 | bool isKey(); | 26 | bool isKey(); |
25 | QString getFile(); | 27 | QString getFile(); |
26 | void setGroup(QString); | 28 | void setGroup(QString); |
27 | QString getGroup(); | 29 | QString getGroup(); |
28 | void setKey(QString); | 30 | void setKey(QString); |
29 | QString getKey(); | 31 | QString getKey(); |
30 | QString getValue(); | 32 | QString getValue(); |
31 | void keyChanged(QString); | 33 | void keyChanged(QString); |
32 | void valueChanged(QString); | 34 | void valueChanged(QString); |
33 | virtual void displayText(); | 35 | virtual void displayText(); |
34 | virtual void changed(); | 36 | virtual void changed(); |
37 | void save(QTextStream*); | ||
35 | private: | 38 | private: |
36 | QString _file; | 39 | QString _file; |
37 | QString _group; | 40 | QString _group; |
38 | QString _key; | 41 | QString _key; |
39 | QString _value; | 42 | QString _value; |
40 | ListViewItemConfFile *_fileItem; | 43 | ListViewItemConfFile *_fileItem; |
41 | }; | 44 | }; |
42 | 45 | ||
43 | #endif | 46 | #endif |
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 30dfdf7..47d9518 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp | |||
@@ -26,78 +26,78 @@ | |||
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 | ||
36 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | 36 | MainWindow::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 | popupTimer = new QTimer(this); | 41 | popupTimer = new QTimer(this); |
42 | popupMenu = new QPopupMenu(this); | 42 | popupMenu = new QPopupMenu(this); |
43 | 43 | ||
44 | QWidget *mainWidget = new QWidget(this); | 44 | QWidget *mainWidget = new QWidget(this); |
45 | setCentralWidget( mainWidget); | 45 | setCentralWidget( mainWidget); |
46 | 46 | ||
47 | QGridLayout *mainLayout = new QGridLayout( mainWidget ); | 47 | QGridLayout *mainLayout = new QGridLayout( mainWidget ); |
48 | mainLayout->setSpacing( 3 ); | 48 | mainLayout->setSpacing( 3 ); |
49 | mainLayout->setMargin( 3 ); | 49 | mainLayout->setMargin( 3 ); |
50 | 50 | ||
51 | 51 | ||
52 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); | 52 | settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); |
53 | mainLayout->addWidget( settingList, 0, 0 ); | 53 | mainLayout->addWidget( settingList, 0, 0 ); |
54 | 54 | ||
55 | editor = new EditWidget(this); | 55 | editor = new EditWidget(this); |
56 | mainLayout->addWidget( editor, 1, 0 ); | 56 | mainLayout->addWidget( editor, 1, 0 ); |
57 | 57 | ||
58 | connect (settingList, SIGNAL( currentChanged(QListViewItem*) ), | 58 | connect(settingList, SIGNAL( pressed(QListViewItem*) ), |
59 | this, SLOT(setCurrent(QListViewItem*))); | 59 | this, SLOT(setCurrent(QListViewItem*))); |
60 | 60 | ||
61 | connect( popupTimer, SIGNAL(timeout()), | 61 | connect( popupTimer, SIGNAL(timeout()), |
62 | this, SLOT(showPopup()) ); | 62 | this, SLOT(showPopup()) ); |
63 | connect( this, SIGNAL( clicked( QListViewItem* ) ), | 63 | connect( settingList, SIGNAL( clicked( QListViewItem* ) ), |
64 | this, SLOT( stopTimer( QListViewItem* ) ) ); | 64 | this, SLOT( stopTimer( QListViewItem* ) ) ); |
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 | if (!item) return; | 89 | if (!item) return; |
90 | ListViewItemConf *i = (ListViewItemConf*) item; | 90 | ListViewItemConf *i = (ListViewItemConf*) item; |
91 | if (!i) return; | 91 | if (!i) return; |
92 | if (i->getType() == ListViewItemConf::File) | 92 | if (i->getType() == ListViewItemConf::File) |
93 | { | 93 | { |
94 | qDebug("start timer"); | 94 | qDebug("start timer"); |
95 | popupTimer->start( 750, true ); | 95 | popupTimer->start( 750, true ); |
96 | editor->hide(); | 96 | editor->hide(); |
97 | updateGeometry(); | 97 | updateGeometry(); |
98 | _currentItem=0; | 98 | _currentItem=0; |
99 | _fileItem = (ListViewItemConfFile*)item; | 99 | _fileItem = (ListViewItemConfFile*)item; |
100 | return; | 100 | return; |
101 | }else editor->show(); | 101 | }else editor->show(); |
102 | _fileItem = 0; | 102 | _fileItem = 0; |
103 | _currentItem = (ListViewItemConfigEntry*)item; | 103 | _currentItem = (ListViewItemConfigEntry*)item; |