author | tille <tille> | 2002-06-29 20:53:42 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-29 20:53:42 (UTC) |
commit | cbb1662a1c3bca476294100ce5e0d0eeb3655639 (patch) (side-by-side diff) | |
tree | e7deb5afdba0d5fa843675669ae3e089c168d022 | |
parent | 5960b3a2823037c63afba09ca83dbcc0943cd082 (diff) | |
download | opie-cbb1662a1c3bca476294100ce5e0d0eeb3655639.zip opie-cbb1662a1c3bca476294100ce5e0d0eeb3655639.tar.gz opie-cbb1662a1c3bca476294100ce5e0d0eeb3655639.tar.bz2 |
makes backups, but does not save the file yet
-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 @@ -1,53 +1,53 @@ /*************************************************************************** * * * 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 "listviewconfdir.h" #include <qmessagebox.h> #include "listviewitemconffile.h" ListViewConfDir::ListViewConfDir(QString settingsPath, QWidget *parent, const char *name ) : QListView(parent,name), confDir(settingsPath) { setRootIsDecorated( true ); addColumn(tr("Files")); if (!confDir.isReadable()) QMessageBox::critical(this,tr("Could not open"),tr("The directory ")+settingsPath+tr(" could not be opened."),1,0); readConfFiles(); } ListViewConfDir::~ListViewConfDir() { } void ListViewConfDir::readConfFiles() { confDir.setFilter( QDir::Files | QDir::NoSymLinks ); confDir.setSorting( QDir::Name ); - + confDir.setNameFilter("*.conf"); const QFileInfoList *list = confDir.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; ListViewItemConfFile *fileEntry; while ( (fi=it.current()) ) { qDebug( "opening: >%s<", fi->fileName().data() ); fileEntry = new ListViewItemConfFile( fi, this ); ++it; } }
\ 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 @@ /*************************************************************************** * * * 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(); - _changed = false; displayText(); } ListViewItemConfFile::~ListViewItemConfFile() { } void ListViewItemConfFile::displayText() { - setText(0,(_changed?"*":"*")+confFileInfo->fileName()); + setText(0,(_changed?"*":"")+confFileInfo->fileName()); } QString ListViewItemConfFile::fileName() { return confFileInfo->fileName(); } void ListViewItemConfFile::parseFile() { - qDebug( confFileInfo->absFilePath() ); QFile confFile(confFileInfo->absFilePath()); - qDebug( confFileInfo->absFilePath() ); - // QString fileName = confFileInfo->fileName(); 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); + // 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(); setExpandable( _valid ); } void ListViewItemConfFile::save() { - qDebug("ListViewItemConfFile::save()"); + if (!_changed) return; + QString backup = confFileInfo->absFilePath()+"~"; + qDebug("make backup to "+backup); + QFile conf(confFileInfo->absFilePath()); + QFile back(backup); + + 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(); + + qDebug("no saveing yet..."); unchanged(); } 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 @@ -1,36 +1,35 @@ /*************************************************************************** * * * 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(); - /** No descriptions */ void save(); protected: private: bool _valid; QFileInfo *confFileInfo; }; #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 @@ -1,195 +1,168 @@ /*************************************************************************** * * * 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") ); popupTimer = new QTimer(this); popupMenu = new QPopupMenu(this); QWidget *mainWidget = new QWidget(this); setCentralWidget( mainWidget); QGridLayout *mainLayout = new QGridLayout( mainWidget ); mainLayout->setSpacing( 3 ); mainLayout->setMargin( 3 ); settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist"); mainLayout->addWidget( settingList, 0, 0 ); editor = new EditWidget(this); mainLayout->addWidget( editor, 1, 0 ); connect (settingList, SIGNAL( currentChanged(QListViewItem*) ), this, SLOT(setCurrent(QListViewItem*))); connect( popupTimer, SIGNAL(timeout()), this, SLOT(showPopup()) ); connect( this, 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&) ), SLOT( keyChanged(const QString&) ) ); connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ), SLOT( valueChanged(const QString&) ) ); makeMenu(); } void MainWindow::makeMenu() { } MainWindow::~MainWindow() { } void MainWindow::setCurrent(QListViewItem *item) { - qDebug("MainWindow::setCurrent("); if (!item) return; - qDebug("cast ListViewItemConf"); ListViewItemConf *i = (ListViewItemConf*) item; if (!i) return; if (i->getType() == ListViewItemConf::File) { + qDebug("start timer"); popupTimer->start( 750, true ); editor->hide(); updateGeometry(); _currentItem=0; _fileItem = (ListViewItemConfFile*)item; return; }else editor->show(); - qDebug("cast ListViewItemConfigEntry"); _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(); } 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::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 ( !activePackage->installed() ) -// { -// popupMenu->insertItem( tr("Install to"), destsMenu ); -// QStringList dests = settings->getDestinationNames(); -// QString ad = settings->getDestinationName(); -// for (uint i = 0; i < dests.count(); i++ ) -// { -// popupAction = new QAction( dests[i], QString::null, 0, this, 0 ); -// popupAction->addTo( destsMenu ); -// if ( dests[i] == ad && activePackage->toInstall() ) -// { -// popupAction->setToggleAction( true ); -// popupAction->setOn(true); -// }; -// } -// connect( destsMenu, SIGNAL( activated( int ) ), -// this, SLOT( changePackageDest( int ) ) ); -// }else{ -// popupAction = new QAction( tr("Remove"),QString::null, 0, this, 0 ); -// popupAction->addTo( popupMenu ); -// connect( popupAction, SIGNAL( activated() ), -// this , SLOT( toggleProcess() ) ); -// popupAction = new QAction( tr("Reinstall"),QString::null, 0, this, 0 ); -// popupAction->addTo( popupMenu ); -// popupAction->setEnabled( false ); -// } + popupMenu->popup( QCursor::pos() ); } |