author | tille <tille> | 2002-06-29 23:23:09 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-29 23:23:09 (UTC) |
commit | 0f179c0cc471b659b30dec4762c9c36678063f31 (patch) (side-by-side diff) | |
tree | 5350dc3b1c05991953011d01ad19cb12414abc1a | |
parent | eb02223de534d315bfdcb0d521719c2d2e9a7235 (diff) | |
download | opie-0f179c0cc471b659b30dec4762c9c36678063f31.zip opie-0f179c0cc471b659b30dec4762c9c36678063f31.tar.gz opie-0f179c0cc471b659b30dec4762c9c36678063f31.tar.bz2 |
revert
-rw-r--r-- | noncore/apps/confedit/listviewitemconf.h | 1 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 30 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.h | 2 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.cpp | 47 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.h | 10 |
5 files changed, 71 insertions, 19 deletions
diff --git a/noncore/apps/confedit/listviewitemconf.h b/noncore/apps/confedit/listviewitemconf.h index 5837625..c6e60ba 100644 --- a/noncore/apps/confedit/listviewitemconf.h +++ b/noncore/apps/confedit/listviewitemconf.h @@ -24,8 +24,9 @@ public: int getType(); virtual void displayText() = 0; virtual void changed(); + bool isChanged() {return _changed;}; virtual void unchanged(); protected: int _type; diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp index 858726d..b075063 100644 --- a/noncore/apps/confedit/listviewitemconffile.cpp +++ b/noncore/apps/confedit/listviewitemconffile.cpp @@ -72,11 +72,34 @@ void ListViewItemConfFile::parseFile() groupItem->insertItem( item ); } } confFile.close(); + unchanged(); setExpandable( _valid ); } + +void ListViewItemConfFile::revert() +{ + if (_changed) + { + parseFile(); + }else{ + QString backup = confFileInfo->absFilePath()+"~"; + QFile conf(confFileInfo->absFilePath()); + QFile back(backup); + + if (!back.open(IO_ReadOnly)) return; + if (!conf.open(IO_WriteOnly)) return; + + #define SIZE 124 + char buf[SIZE]; + while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); + conf.close(); + back.close(); + } +} + void ListViewItemConfFile::save() { if (!_changed) return; QString backup = confFileInfo->absFilePath()+"~"; @@ -100,7 +123,12 @@ void ListViewItemConfFile::save() { ((ListViewItemConfigEntry*)it)->save(t); } conf.close(); - qDebug("no saveing yet..."); unchanged(); } + + +bool ListViewItemConfFile::revertable() +{ + return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); +}
\ No newline at end of file diff --git a/noncore/apps/confedit/listviewitemconffile.h b/noncore/apps/confedit/listviewitemconffile.h index d89b19c..ae23eab 100644 --- a/noncore/apps/confedit/listviewitemconffile.h +++ b/noncore/apps/confedit/listviewitemconffile.h @@ -24,9 +24,11 @@ public: ~ListViewItemConfFile(); void parseFile(); QString fileName(); virtual void displayText(); + bool revertable(); void save(); + void revert(); protected: private: bool _valid; QFileInfo *confFileInfo; diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp index 47d9518..77b91f6 100644 --- a/noncore/apps/confedit/mainwindow.cpp +++ b/noncore/apps/confedit/mainwindow.cpp @@ -37,11 +37,8 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0) { setCaption( tr("Conf File Editor") ); - popupTimer = new QTimer(this); - popupMenu = new QPopupMenu(this); - QWidget *mainWidget = new QWidget(this); setCentralWidget( mainWidget); QGridLayout *mainLayout = new QGridLayout( mainWidget ); @@ -57,12 +54,8 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : connect(settingList, SIGNAL( pressed(QListViewItem*) ), this, SLOT(setCurrent(QListViewItem*))); - connect( popupTimer, SIGNAL(timeout()), - this, SLOT(showPopup()) ); - connect( settingList, SIGNAL( clicked( QListViewItem* ) ), - this, SLOT( stopTimer( QListViewItem* ) ) ); connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), SLOT( groupChanged(const QString&) ) ); connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), @@ -75,8 +68,24 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : void MainWindow::makeMenu() { + popupTimer = new QTimer(this); + popupMenuFile = new QPopupMenu(this); + + popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); + popupActionSave->addTo( popupMenuFile ); + connect( popupActionSave, SIGNAL( activated() ), + this , SLOT( saveConfFile() ) ); + popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); + popupActionRevert->addTo( popupMenuFile ); + connect( popupActionRevert, SIGNAL( activated() ), + this , SLOT( revertConfFile() ) ); + + connect( popupTimer, SIGNAL(timeout()), + this, SLOT(showPopup()) ); + connect( settingList, SIGNAL( clicked( QListViewItem* ) ), + this, SLOT( stopTimer( QListViewItem* ) ) ); } MainWindow::~MainWindow() { @@ -150,19 +159,23 @@ void MainWindow::saveConfFile() if (!_fileItem) return; _fileItem->save(); } +void MainWindow::revertConfFile() +{ + if (!_fileItem) return; + _fileItem->revert(); +} + void MainWindow::showPopup() { qDebug("showPopup"); - if (!_fileItem) return; - popupMenu->clear(); - - QAction *popupAction; - popupAction = new QAction( tr("Save"),QString::null, 0, this, 0 ); - popupAction->addTo( popupMenu ); - connect( popupAction, SIGNAL( activated() ), - this , SLOT( saveConfFile() ) ); - + if (_fileItem) + { + popupActionSave->setEnabled(_fileItem->isChanged()); + popupActionRevert->setEnabled(_fileItem->revertable()); + popupMenuFile->popup( QCursor::pos() ); + }else if(_currentItem->isChanged()) + { - popupMenu->popup( QCursor::pos() ); + } } diff --git a/noncore/apps/confedit/mainwindow.h b/noncore/apps/confedit/mainwindow.h index b015dac..e0dc0b0 100644 --- a/noncore/apps/confedit/mainwindow.h +++ b/noncore/apps/confedit/mainwindow.h @@ -40,16 +40,24 @@ public slots: void valueChanged(const QString&); void showPopup(); void stopTimer( QListViewItem* ); void saveConfFile(); + void revertConfFile(); private: ListViewConfDir *settingList; EditWidget *editor; ListViewItemConfigEntry *_currentItem; ListViewItemConfFile *_fileItem; QTimer *popupTimer; - QPopupMenu *popupMenu; + QPopupMenu *popupMenuFile; + QPopupMenu *popupMenuEntry; + QAction *popupActionSave; + QAction *popupActionRevert; + QAction *popupActionDelete; + QAction *popupActionNew; +// QAction *popupAction; +// QAction *popupAction; void makeMenu(); }; |