-rw-r--r-- | noncore/apps/confedit/listviewitemconf.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconf.h | 4 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 24 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.h | 8 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.cpp | 18 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconfigentry.h | 5 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 65 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.h | 4 |
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 | |||
@@ -44,3 +44,8 @@ void ListViewItemConf::unchanged() | |||
44 | } | 44 | } |
45 | displayText(); | 45 | displayText(); |
46 | } | ||
47 | |||
48 | bool 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 | |||
@@ -24,8 +24,12 @@ public: | |||
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 | ||
31 | protected: | 35 | protected: |
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 | |||
@@ -79,4 +79,11 @@ void ListViewItemConfFile::parseFile() | |||
79 | 79 | ||
80 | 80 | ||
81 | void ListViewItemConfFile::remove() | ||
82 | { | ||
83 | QFile::remove(confFileInfo->absFilePath()); | ||
84 | QFile::remove(backupFileName()); | ||
85 | delete this; | ||
86 | } | ||
87 | |||
81 | void ListViewItemConfFile::revert() | 88 | void ListViewItemConfFile::revert() |
82 | { | 89 | { |
@@ -85,7 +92,6 @@ void ListViewItemConfFile::revert() | |||
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; |
@@ -103,13 +109,10 @@ void 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); |
@@ -131,4 +134,9 @@ void ListViewItemConfFile::save() | |||
131 | bool ListViewItemConfFile::revertable() | 134 | bool 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 | |||
139 | QString 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 | |||
@@ -25,8 +25,10 @@ public: | |||
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(); | ||
31 | protected: | 33 | protected: |
32 | private: | 34 | private: |
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 | |||
@@ -20,4 +20,7 @@ ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, Q | |||
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 | } |
@@ -108,4 +111,10 @@ void ListViewItemConfigEntry::changed() | |||
108 | } | 111 | } |
109 | 112 | ||
113 | |||
114 | void ListViewItemConfigEntry::remove() | ||
115 | { | ||
116 | delete this; | ||
117 | } | ||
118 | |||
110 | void ListViewItemConfigEntry::save(QTextStream *t) | 119 | void ListViewItemConfigEntry::save(QTextStream *t) |
111 | { | 120 | { |
@@ -126,3 +135,12 @@ void ListViewItemConfigEntry::save(QTextStream *t) | |||
126 | ((ListViewItemConfigEntry*)it)->save(t); | 135 | ((ListViewItemConfigEntry*)it)->save(t); |
127 | } | 136 | } |
137 | } | ||
138 | |||
139 | void 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 | |||
@@ -35,5 +35,7 @@ public: | |||
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(); | ||
38 | private: | 40 | private: |
39 | QString _file; | 41 | QString _file; |
@@ -41,4 +43,7 @@ private: | |||
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 | }; |
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 | |||
@@ -41,5 +41,4 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
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 ); |
@@ -47,10 +46,18 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
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*))); |
@@ -63,27 +70,44 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | |||
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 | ||
68 | void MainWindow::makeMenu() | 79 | void 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 | ||
@@ -97,10 +121,9 @@ void 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(); |
@@ -127,4 +150,6 @@ void MainWindow::setCurrent(QListViewItem *item) | |||
127 | } | 150 | } |
128 | updateGeometry(); | 151 | updateGeometry(); |
152 | editor->updateGeometry(); | ||
153 | settingList->updateGeometry(); | ||
129 | } | 154 | } |
130 | 155 | ||
@@ -151,5 +176,4 @@ void MainWindow::valueChanged(const QString &v) | |||
151 | void MainWindow::stopTimer( QListViewItem* ) | 176 | void MainWindow::stopTimer( QListViewItem* ) |
152 | { | 177 | { |
153 | qDebug("stopTimer"); | ||
154 | popupTimer->stop(); | 178 | popupTimer->stop(); |
155 | } | 179 | } |
@@ -163,19 +187,26 @@ void MainWindow::saveConfFile() | |||
163 | void MainWindow::revertConfFile() | 187 | void MainWindow::revertConfFile() |
164 | { | 188 | { |
165 | if (!_fileItem) return; | 189 | if (!_item) return; |
166 | _fileItem->revert(); | 190 | _item->revert(); |
167 | } | 191 | } |
168 | 192 | ||
193 | void MainWindow::removeConfFile() | ||
194 | { | ||
195 | if (!_item) return; | ||
196 | _item->remove(); | ||
197 | } | ||
169 | void MainWindow::showPopup() | 198 | void MainWindow::showPopup() |
170 | { | 199 | { |
171 | qDebug("showPopup"); | 200 | qDebug("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 | |||
@@ -22,5 +22,5 @@ class QPEToolBar; | |||
22 | class ListViewItemConfFile; | 22 | class ListViewItemConfFile; |
23 | class ListViewConfDir; | 23 | class ListViewConfDir; |
24 | 24 | class ListViewItemConf; | |
25 | 25 | ||
26 | class MainWindow : public QMainWindow | 26 | class MainWindow : public QMainWindow |
@@ -43,8 +43,10 @@ public slots: | |||
43 | void saveConfFile(); | 43 | void saveConfFile(); |
44 | void revertConfFile(); | 44 | void revertConfFile(); |
45 | void removeConfFile(); | ||
45 | 46 | ||
46 | private: | 47 | private: |
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; |