author | tille <tille> | 2002-06-30 01:05:42 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-30 01:05:42 (UTC) |
commit | 064b3d7b91a526a64c22facba228e3c2fec8fdc8 (patch) (side-by-side diff) | |
tree | 98221da79a27bc13b8214b92c8c936c529312e24 | |
parent | 1f9e13bb2d287a2495e2cbb0f8be0f53c883eae2 (diff) | |
download | opie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.zip opie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.tar.gz opie-064b3d7b91a526a64c22facba228e3c2fec8fdc8.tar.bz2 |
late night
-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 | 22 | ||||
-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 | 63 | ||||
-rw-r--r-- | noncore/apps/confedit/mainwindow.h | 4 |
8 files changed, 102 insertions, 27 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 @@ -1,46 +1,51 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "listviewitemconf.h" ListViewItemConf::ListViewItemConf(ListViewItemConf *parent) : QListViewItem(parent), _changed(false) { } ListViewItemConf::ListViewItemConf(QListView *parent) : QListViewItem(parent), _changed(false) { _type = File; } ListViewItemConf::~ListViewItemConf() { } int ListViewItemConf::getType() { return _type; } void ListViewItemConf::changed() { _changed=true; displayText(); } void ListViewItemConf::unchanged() { _changed=false; for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConf*)it)->unchanged(); } displayText(); }
\ No newline at end of file + +bool ListViewItemConf::revertable() +{ + return _changed; +}
\ 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 @@ -1,36 +1,40 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef LISTVIEWITEMCONF_H #define LISTVIEWITEMCONF_H #include <qlistview.h> class ListViewItemConf : public QListViewItem { public: enum {File, Group, Key}; ListViewItemConf(ListViewItemConf *parent); ListViewItemConf(QListView *parent); ~ListViewItemConf(); int getType(); + void save(); + virtual void revert() = 0; + virtual void remove() = 0; virtual void displayText() = 0; virtual void changed(); bool isChanged() {return _changed;}; virtual void unchanged(); + virtual bool revertable(); protected: int _type; bool _changed; }; #endif 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 @@ -1,134 +1,142 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #include "listviewitemconffile.h" #include <qmessagebox.h> #include <qtextstream.h> #include <qstring.h> #include "listviewitemconfigentry.h" #define tr QObject::tr ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) : ListViewItemConf(parent), _valid(false) { confFileInfo = file; parseFile(); displayText(); } ListViewItemConfFile::~ListViewItemConfFile() { } void ListViewItemConfFile::displayText() { setText(0,(_changed?"*":"")+confFileInfo->fileName()); } QString ListViewItemConfFile::fileName() { return confFileInfo->fileName(); } void ListViewItemConfFile::parseFile() { QFile confFile(confFileInfo->absFilePath()); if(! confFile.open(IO_ReadOnly)) QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); QTextStream t( &confFile ); QString s; QString group; ListViewItemConfigEntry *groupItem; ListViewItemConfigEntry *item; while ( !t.atEnd() ) { s = t.readLine().stripWhiteSpace(); // qDebug( "line: >%s<\n", s.latin1() ); if (s.contains("<?xml")) { _valid = false; break; }else if ( s[0] == '[' && s[s.length()-1] == ']' ) { // qDebug("got group"+s); group = s.mid(1,s.length()-2); groupItem = new ListViewItemConfigEntry(this, group ); insertItem( groupItem ); } else if ( int pos = s.find('=') ) { // qDebug("got key"+s); item = new ListViewItemConfigEntry(this, group, s ); groupItem->insertItem( item ); } } confFile.close(); unchanged(); setExpandable( _valid ); } +void ListViewItemConfFile::remove() +{ + QFile::remove(confFileInfo->absFilePath()); + QFile::remove(backupFileName()); + delete this; +} + void ListViewItemConfFile::revert() { if (_changed) { parseFile(); }else{ - QString backup = confFileInfo->absFilePath()+"~"; QFile conf(confFileInfo->absFilePath()); - QFile back(backup); + QFile back(backupFileName()); 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()+"~"; - qDebug("make backup to "+backup); QFile conf(confFileInfo->absFilePath()); - QFile back(backup); + QFile back(backupFileName()); if (!conf.open(IO_ReadOnly)) return; if (!back.open(IO_WriteOnly)) return; - #define SIZE 124 char buf[SIZE]; while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); conf.close(); back.close(); if (!conf.open(IO_WriteOnly)) return; QTextStream *t = new QTextStream( &conf ); for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConfigEntry*)it)->save(t); } conf.close(); unchanged(); } bool ListViewItemConfFile::revertable() { - return _changed || QFile(confFileInfo->absFilePath()+"~").exists(); + return _changed || QFile(backupFileName()).exists(); +} + +QString ListViewItemConfFile::backupFileName() +{ + return confFileInfo->absFilePath()+"~"; }
\ No newline at end of file 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 @@ -1,37 +1,39 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #ifndef LISTVIEWITEMCONFFILE_H #define LISTVIEWITEMCONFFILE_H #include <qwidget.h> #include <qlistview.h> #include <qfile.h> #include <qfileinfo.h> #include "listviewitemconf.h" class ListViewItemConfFile : public ListViewItemConf { public: ListViewItemConfFile(QFileInfo *file, QListView *parent=0); ~ListViewItemConfFile(); void parseFile(); QString fileName(); - virtual void displayText(); - bool revertable(); void save(); - void revert(); + virtual void displayText(); + virtual bool revertable(); + virtual void revert(); + virtual void remove(); + QString backupFileName(); protected: private: bool _valid; QFileInfo *confFileInfo; }; #endif 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 @@ -1,128 +1,146 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogtp <tille@handhelds.org> #include "listviewitemconfigentry.h" #include "listviewitemconffile.h" #include <qtextstream.h> ListViewItemConfigEntry::ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key) : ListViewItemConf(parent) { _fileItem = parent; _file = parent->fileName(); _group = group; setKey(key); + _groupOrig = group; + _keyOrig = _key; + _valueOrig = _value; _fileItem->unchanged(); } ListViewItemConfigEntry::~ListViewItemConfigEntry() { } bool ListViewItemConfigEntry::isGroup() { return _key.isEmpty(); } bool ListViewItemConfigEntry::isKey() { return !_key.isEmpty(); } QString ListViewItemConfigEntry::getFile() { return _file; } void ListViewItemConfigEntry::setGroup(QString g) { if (g==_group) return; _group = g; changed(); } QString ListViewItemConfigEntry::getGroup() { return _group; } void ListViewItemConfigEntry::setKey(QString key) { int pos = key.find("="); _key = key.left(pos).stripWhiteSpace(); _value = key.right(key.length() - pos - 1).stripWhiteSpace(); displayText(); } QString ListViewItemConfigEntry::getKey() { return _key; } QString ListViewItemConfigEntry::getValue() { return _value; } void ListViewItemConfigEntry::keyChanged(QString k) { if (k==_key) return; _key = k; changed(); } void ListViewItemConfigEntry::valueChanged(QString v) { if (v==_value) return; _value = v; changed(); } void ListViewItemConfigEntry::displayText() { QString s; if (_changed) s="*"; if (isGroup()) { s += "["+_group+"]"; _type = Group; }else{ s += _key+" = "+_value; _type = Key; } setText(0,s); } void ListViewItemConfigEntry::changed() { _changed=true; displayText(); _fileItem->changed(); } + +void ListViewItemConfigEntry::remove() +{ + delete this; +} + void ListViewItemConfigEntry::save(QTextStream *t) { QString s; if (isGroup()) { s += "["+_group+"]"; _type = Group; }else{ s += _key+" = "+_value; _type = Key; } s += "\n"; (*t) << s; _changed = false; for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConfigEntry*)it)->save(t); } }
\ No newline at end of file + +void ListViewItemConfigEntry::revert() +{ + _group = _groupOrig; + _key = _keyOrig; + _value = _valueOrig; + _changed=false; + displayText(); +}
\ 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 @@ -1,46 +1,51 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogtp <tille@handhelds.org> #ifndef LISTVIEWITEMCONFIGENTRY_H #define LISTVIEWITEMCONFIGENTRY_H #include <qwidget.h> #include <qlistview.h> #include "listviewitemconffile.h" #include "listviewitemconf.h" class QTextStream; class ListViewItemConfigEntry : public ListViewItemConf { public: ListViewItemConfigEntry(ListViewItemConfFile *parent, QString group, QString key=""); ~ListViewItemConfigEntry(); bool isGroup(); bool isKey(); QString getFile(); void setGroup(QString); QString getGroup(); void setKey(QString); QString getKey(); QString getValue(); void keyChanged(QString); void valueChanged(QString); virtual void displayText(); virtual void changed(); + virtual void remove(); void save(QTextStream*); + virtual void revert(); private: QString _file; QString _group; QString _key; QString _value; + QString _groupOrig; + QString _keyOrig; + QString _valueOrig; ListViewItemConfFile *_fileItem; }; #endif 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 @@ -1,181 +1,212 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #include "mainwindow.h" #include <qpe/qpemenubar.h> #include <qpe/qpemessagebox.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/qpetoolbar.h> #include <qaction.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qtoolbutton.h> #include <qstring.h> #include <qlabel.h> #include <qfile.h> #include <qpushbutton.h> #include <qlayout.h> #include <qlineedit.h> #include "listviewconfdir.h" #include "listviewitemconf.h" #include "listviewitemconfigentry.h" MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0) { setCaption( tr("Conf File Editor") ); QWidget *mainWidget = new QWidget(this); setCentralWidget( mainWidget); - QGridLayout *mainLayout = new QGridLayout( mainWidget ); mainLayout->setSpacing( 3 ); mainLayout->setMargin( 3 ); + qDebug("settingList"); settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); + settingList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding));//, sizePolicy().hasHeightForWidth() ) ); mainLayout->addWidget( settingList, 0, 0 ); + qDebug("editor"); editor = new EditWidget(this); + editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum));//, sizePolicy().hasHeightForWidth() ) ); +// editor->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3));//, sizePolicy().hasHeightForWidth() ) ); mainLayout->addWidget( editor, 1, 0 ); + makeMenu(); + + qDebug("connect"); connect(settingList, SIGNAL( pressed(QListViewItem*) ), this, SLOT(setCurrent(QListViewItem*))); connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ), SLOT( groupChanged(const QString&) ) ); connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ), SLOT( keyChanged(const QString&) ) ); connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), SLOT( valueChanged(const QString&) ) ); - makeMenu(); +// qDebug("editor->hide()"); +// editor->hide(); + qDebug("connect"); + connect( settingList, SIGNAL( clicked( QListViewItem* ) ), + this, SLOT( stopTimer( QListViewItem* ) ) ); } void MainWindow::makeMenu() { - + qDebug("MainWindow::makeMenu()"); popupTimer = new QTimer(this); popupMenuFile = new QPopupMenu(this); + popupMenuEntry = new QPopupMenu(this); + qDebug("Save"); popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 ); popupActionSave->addTo( popupMenuFile ); + // popupActionSave->addTo( popupMenuEntry ); connect( popupActionSave, SIGNAL( activated() ), this , SLOT( saveConfFile() ) ); + + qDebug("Revert"); popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 ); popupActionRevert->addTo( popupMenuFile ); + popupActionRevert->addTo( popupMenuEntry ); connect( popupActionRevert, SIGNAL( activated() ), this , SLOT( revertConfFile() ) ); + qDebug("Delete"); + popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 ); + popupActionDelete->addTo( popupMenuFile ); + popupActionDelete->addTo( popupMenuEntry ); + connect( popupActionDelete, SIGNAL( activated() ), + this , SLOT( removeConfFile() ) ); + + qDebug("connect"); connect( popupTimer, SIGNAL(timeout()), this, SLOT(showPopup()) ); - connect( settingList, SIGNAL( clicked( QListViewItem* ) ), - this, SLOT( stopTimer( QListViewItem* ) ) ); + qDebug("connect"); } MainWindow::~MainWindow() { } void MainWindow::setCurrent(QListViewItem *item) { if (!item) return; - ListViewItemConf *i = (ListViewItemConf*) item; - if (!i) return; - if (i->getType() == ListViewItemConf::File) - { - qDebug("start timer"); + _item = (ListViewItemConf*) item; + if (!_item) return; popupTimer->start( 750, true ); + if (_item->getType() == ListViewItemConf::File) + { editor->hide(); updateGeometry(); _currentItem=0; _fileItem = (ListViewItemConfFile*)item; return; }else editor->show(); _fileItem = 0; _currentItem = (ListViewItemConfigEntry*)item; if (!_currentItem) return; QString file = _currentItem->getFile(); QString group = _currentItem->getGroup(); QString key = _currentItem->getKey(); QString val = _currentItem->getValue(); editor->TextFileName->setText(file); editor->LineEditGroup->setText(group); if (!key.isEmpty()) { editor->isKey(true); editor->LineEditKey->setText(key); editor->LineEditValue->setText(val); }else{ editor->isKey(false); } updateGeometry(); + editor->updateGeometry(); + settingList->updateGeometry(); } void MainWindow::groupChanged(const QString &g) { if (!_currentItem) return; _currentItem->setGroup(g); } void MainWindow::keyChanged(const QString &k) { if (!_currentItem) return; _currentItem->keyChanged(k); } void MainWindow::valueChanged(const QString &v) { if (!_currentItem) return; _currentItem->valueChanged(v); } void MainWindow::stopTimer( QListViewItem* ) { - qDebug("stopTimer"); popupTimer->stop(); } void MainWindow::saveConfFile() { if (!_fileItem) return; _fileItem->save(); } void MainWindow::revertConfFile() { - if (!_fileItem) return; - _fileItem->revert(); + if (!_item) return; + _item->revert(); } +void MainWindow::removeConfFile() +{ + if (!_item) return; + _item->remove(); +} void MainWindow::showPopup() { qDebug("showPopup"); + if (!_item) return; + popupActionRevert->setEnabled(_item->revertable()); + popupActionSave->setEnabled(_item->isChanged()); if (_fileItem) { popupActionSave->setEnabled(_fileItem->isChanged()); - popupActionRevert->setEnabled(_fileItem->revertable()); popupMenuFile->popup( QCursor::pos() ); - }else if(_currentItem->isChanged()) + }else if(_currentItem) { - + popupMenuEntry->popup( QCursor::pos() ); } } 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 @@ -1,64 +1,66 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> #include <qaction.h> #include <qtimer.h> #include <qpopupmenu.h> #include "editwidget.h" class QPEToolBar; class ListViewItemConfFile; class ListViewConfDir; - +class ListViewItemConf; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~MainWindow(); public slots: void setCurrent(QListViewItem*); void groupChanged(const QString&); void keyChanged(const QString&); void valueChanged(const QString&); void showPopup(); void stopTimer( QListViewItem* ); void saveConfFile(); void revertConfFile(); + void removeConfFile(); private: ListViewConfDir *settingList; EditWidget *editor; + ListViewItemConf *_item; ListViewItemConfigEntry *_currentItem; ListViewItemConfFile *_fileItem; QTimer *popupTimer; QPopupMenu *popupMenuFile; QPopupMenu *popupMenuEntry; QAction *popupActionSave; QAction *popupActionRevert; QAction *popupActionDelete; QAction *popupActionNew; // QAction *popupAction; // QAction *popupAction; void makeMenu(); }; #endif |