--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#include "dialogfileplaceholder.hpp"
+#include "ui_dialogfileplaceholders.h"
+
+DialogFilePlaceholder::DialogFilePlaceholder(QWidget *parent) :
+ QDialog(parent), ui(new Ui::DialogFilePlaceHolders){
+ ui->setupUi(this);
+ connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
+}
+
+DialogFilePlaceholder::~DialogFilePlaceholder(){
+ delete ui;
+}
+
+/**
+ * Handles the push of the OK button.
+ */
+void DialogFilePlaceholder::ok(){
+ int row = ui->tableWidget->currentRow();
+ if (row >= 0)
+ m_var = ui->tableWidget->item(row, COL_VAR)->text();
+ close();
+}
+/**
+ * Returns the selected placeholder.
+ *
+ * @return "": nothing selected<br>
+ * otherwise: the name of the selected placeholder
+ */
+QString DialogFilePlaceholder::var() const{
+ return m_var;
+}
+
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#ifndef DIALOGLINEPLACEHOLDERS_HPP
+#define DIALOGLINEPLACEHOLDERS_HPP
+
+#include <QDialog>
+
+namespace Ui {
+class DialogFilePlaceHolders;
+}
+
+class DialogFilePlaceholder: public QDialog {
+ Q_OBJECT
+
+public:
+ enum {
+ COL_VAR, COL_EXAMPLE, COL_DESCR
+ };
+public:
+ explicit DialogFilePlaceholder(QWidget *parent = 0);
+ ~DialogFilePlaceholder();
+public:
+ QString var() const;public slots:
+ void ok();
+
+private:
+ Ui::DialogFilePlaceHolders *ui;
+ QString m_var;
+};
+
+#endif // DIALOGLINEPLACEHOLDERS_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogFilePlaceHolders</class>
+ <widget class="QDialog" name="DialogFilePlaceHolders">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>429</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>File Specific Placeholders</string>
+ </property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>380</y>
+ <width>341</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QTableWidget" name="tableWidget">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>761</width>
+ <height>351</height>
+ </rect>
+ </property>
+ <attribute name="horizontalHeaderDefaultSectionSize">
+ <number>190</number>
+ </attribute>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <column>
+ <property name="text">
+ <string>Placeholder</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Example</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Description</string>
+ </property>
+ </column>
+ <item row="0" column="0">
+ <property name="text">
+ <string>${base}</string>
+ </property>
+ </item>
+ <item row="0" column="1">
+ <property name="text">
+ <string>/home/bob</string>
+ </property>
+ </item>
+ <item row="0" column="2">
+ <property name="text">
+ <string>base directory</string>
+ </property>
+ </item>
+ <item row="1" column="0">
+ <property name="text">
+ <string notr="true">${full}</string>
+ </property>
+ </item>
+ <item row="1" column="1">
+ <property name="text">
+ <string notr="true">/home/bob/doc/intro.txt</string>
+ </property>
+ </item>
+ <item row="1" column="2">
+ <property name="text">
+ <string>filename with absolute path</string>
+ </property>
+ </item>
+ <item row="2" column="0">
+ <property name="text">
+ <string notr="true">${path}</string>
+ </property>
+ </item>
+ <item row="2" column="1">
+ <property name="text">
+ <string notr="true">doc</string>
+ </property>
+ </item>
+ <item row="2" column="2">
+ <property name="text">
+ <string>relative path</string>
+ </property>
+ </item>
+ <item row="3" column="0">
+ <property name="text">
+ <string notr="true">${node}</string>
+ </property>
+ </item>
+ <item row="3" column="1">
+ <property name="text">
+ <string notr="true">intro.txt</string>
+ </property>
+ </item>
+ <item row="3" column="2">
+ <property name="text">
+ <string>filename with extension</string>
+ </property>
+ </item>
+ <item row="4" column="0">
+ <property name="text">
+ <string notr="true">${name}</string>
+ </property>
+ </item>
+ <item row="4" column="1">
+ <property name="text">
+ <string notr="true">intro</string>
+ </property>
+ </item>
+ <item row="4" column="2">
+ <property name="text">
+ <string>filename without extension</string>
+ </property>
+ </item>
+ <item row="5" column="0">
+ <property name="text">
+ <string notr="true">${ext}</string>
+ </property>
+ </item>
+ <item row="5" column="1">
+ <property name="text">
+ <string notr="true">.txt</string>
+ </property>
+ </item>
+ <item row="5" column="2">
+ <property name="text">
+ <string>extension</string>
+ </property>
+ </item>
+ <item row="6" column="0">
+ <property name="text">
+ <string notr="true">${modified}</string>
+ </property>
+ </item>
+ <item row="6" column="1">
+ <property name="text">
+ <string notr="true">2015.04.03/08:07:14</string>
+ </property>
+ </item>
+ <item row="6" column="2">
+ <property name="text">
+ <string>date/time of the last change</string>
+ </property>
+ </item>
+ <item row="7" column="0">
+ <property name="text">
+ <string notr="true">${size}</string>
+ </property>
+ </item>
+ <item row="7" column="1">
+ <property name="text">
+ <string notr="true">0.001223</string>
+ </property>
+ </item>
+ <item row="7" column="2">
+ <property name="text">
+ <string>file length in megabyte</string>
+ </property>
+ </item>
+ <item row="8" column="0">
+ <property name="text">
+ <string notr="true">${type}</string>
+ </property>
+ </item>
+ <item row="8" column="1">
+ <property name="text">
+ <string notr="true">file</string>
+ </property>
+ </item>
+ <item row="8" column="2">
+ <property name="text">
+ <string>'file', 'dir', 'link (file)', 'link (dir)'</string>
+ </property>
+ </item>
+ <item row="9" column="0">
+ <property name="text">
+ <string>\t</string>
+ </property>
+ </item>
+ <item row="9" column="1">
+ <property name="text">
+ <string notr="true">\t</string>
+ </property>
+ </item>
+ <item row="9" column="2">
+ <property name="text">
+ <string>tabulator</string>
+ </property>
+ </item>
+ <item row="10" column="0">
+ <property name="text">
+ <string notr="true">\n</string>
+ </property>
+ </item>
+ <item row="10" column="1">
+ <property name="text">
+ <string notr="true">\n</string>
+ </property>
+ </item>
+ <item row="10" column="2">
+ <property name="text">
+ <string>newline</string>
+ </property>
+ </item>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>DialogFilePlaceHolders</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>DialogFilePlaceHolders</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#include "dialogglobalplaceholder.hpp"
+#include "ui_dialogglobalplaceholder.h"
+
+DialogGlobalPlaceholder::DialogGlobalPlaceholder(QWidget *parent) :
+ QDialog(parent), ui(new Ui::DialogGlobalPlaceholder), m_var(){
+ ui->setupUi(this);
+ connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(ok()));
+}
+
+DialogGlobalPlaceholder::~DialogGlobalPlaceholder(){
+ delete ui;
+}
+
+/**
+ * Handles the push of the OK button.
+ */
+void DialogGlobalPlaceholder::ok(){
+ int row = ui->tableWidget->currentRow();
+ if (row >= 0)
+ m_var = ui->tableWidget->item(row, COL_VAR)->text();
+ close();
+}
+
+/**
+ * Returns the selected placeholder.
+ *
+ * @return "": nothing selected<br>
+ * otherwise: the name of the selected placeholder
+ */
+QString DialogGlobalPlaceholder::var() const{
+ return m_var;
+}
+
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+ */
+
+#ifndef DIALOGGLOBALPLACEHOLDER_HPP
+#define DIALOGGLOBALPLACEHOLDER_HPP
+
+#include <QDialog>
+
+namespace Ui {
+class DialogGlobalPlaceholder;
+}
+
+class DialogGlobalPlaceholder: public QDialog {
+ Q_OBJECT
+public:
+ enum {
+ COL_VAR, COL_DESCR
+ };
+
+public:
+ explicit DialogGlobalPlaceholder(QWidget *parent = 0);
+ ~DialogGlobalPlaceholder();
+public:
+ QString var() const;
+
+public slots:
+ void ok();
+private:
+ Ui::DialogGlobalPlaceholder *ui;
+ QString m_var;
+};
+
+#endif // DIALOGGLOBALPLACEHOLDER_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogGlobalPlaceholder</class>
+ <widget class="QDialog" name="DialogGlobalPlaceholder">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>583</width>
+ <height>470</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Placeholders for Header and Footer</string>
+ </property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>220</x>
+ <y>420</y>
+ <width>341</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QTableWidget" name="tableWidget">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>541</width>
+ <height>391</height>
+ </rect>
+ </property>
+ <attribute name="horizontalHeaderDefaultSectionSize">
+ <number>150</number>
+ </attribute>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <row>
+ <property name="text">
+ <string>New Row</string>
+ </property>
+ </row>
+ <column>
+ <property name="text">
+ <string>Placeholder</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Description</string>
+ </property>
+ </column>
+ <item row="0" column="0">
+ <property name="text">
+ <string>${datetime}</string>
+ </property>
+ </item>
+ <item row="0" column="1">
+ <property name="text">
+ <string>current date/time</string>
+ </property>
+ </item>
+ <item row="1" column="0">
+ <property name="text">
+ <string>${filepatterns}</string>
+ </property>
+ </item>
+ <item row="1" column="1">
+ <property name="text">
+ <string>current file patterns</string>
+ </property>
+ </item>
+ <item row="2" column="0">
+ <property name="text">
+ <string>${textpattern}</string>
+ </property>
+ </item>
+ <item row="2" column="1">
+ <property name="text">
+ <string>current text pattern</string>
+ </property>
+ </item>
+ <item row="3" column="0">
+ <property name="text">
+ <string>${dirs}</string>
+ </property>
+ </item>
+ <item row="3" column="1">
+ <property name="text">
+ <string>count of found directories</string>
+ </property>
+ </item>
+ <item row="4" column="0">
+ <property name="text">
+ <string>${files}</string>
+ </property>
+ </item>
+ <item row="4" column="1">
+ <property name="text">
+ <string>count of found files</string>
+ </property>
+ </item>
+ <item row="5" column="0">
+ <property name="text">
+ <string>${bytes}</string>
+ </property>
+ </item>
+ <item row="5" column="1">
+ <property name="text">
+ <string>sum of the lengths of the found files</string>
+ </property>
+ </item>
+ <item row="6" column="0">
+ <property name="text">
+ <string>${megabytes}</string>
+ </property>
+ </item>
+ <item row="6" column="1">
+ <property name="text">
+ <string>sum of the lengths of the found files in MBytes</string>
+ </property>
+ </item>
+ <item row="7" column="0">
+ <property name="text">
+ <string>${runtime}</string>
+ </property>
+ </item>
+ <item row="7" column="1">
+ <property name="text">
+ <string>runtime of the search in seconds</string>
+ </property>
+ </item>
+ <item row="8" column="0">
+ <property name="text">
+ <string>\n</string>
+ </property>
+ </item>
+ <item row="8" column="1">
+ <property name="text">
+ <string>newline (line feed)</string>
+ </property>
+ </item>
+ <item row="9" column="0">
+ <property name="text">
+ <string>\r</string>
+ </property>
+ </item>
+ <item row="9" column="1">
+ <property name="text">
+ <string>newline character (carriage return)</string>
+ </property>
+ </item>
+ <item row="10" column="0">
+ <property name="text">
+ <string>\t</string>
+ </property>
+ </item>
+ <item row="10" column="1">
+ <property name="text">
+ <string>tabulator</string>
+ </property>
+ </item>
+ <item row="11" column="0">
+ <property name="text">
+ <string>\\</string>
+ </property>
+ </item>
+ <item row="11" column="1">
+ <property name="text">
+ <string>backslash</string>
+ </property>
+ </item>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>DialogGlobalPlaceholder</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>DialogGlobalPlaceholder</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
#include "mainwindow.hpp"
int main(int argc, char *argv[]){
- QApplication a(argc, argv);
- MainWindow w(argc > 1 ? argv[1] : "");
+ QApplication app(argc, argv);
+ QString startDir = argc > 1 ? argv[1] : "";
+ QString homeDir = argc > 2 ? argv[2] : "";
+ MainWindow w(startDir, homeDir);
+
+ QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(closing()));
+
w.show();
- return a.exec();
+ return app.exec();
}
#include "textfinder.hpp"
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
+#include "dialogfileplaceholder.hpp"
+#include "dialogglobalplaceholder.hpp"
#include "filefinder.hpp"
#include "aboutdialog.hpp"
*
* @param parent NULL or the parent widget
*/
-MainWindow::MainWindow(const QString& startDir, QWidget *parent) :
+MainWindow::MainWindow(const QString& startDir, const QString& homeDir,
+ QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_statusMessage(NULL),
m_textFinder(),
m_lastBaseDir(),
m_horizontalHeader(NULL),
- m_lastOrder(Qt::DescendingOrder){
+ m_lastOrder(Qt::DescendingOrder),
+ m_homeDir(),
+ m_storageFile(){
ui->setupUi(this);
+ initializeHome();
m_statusMessage = new QLabel(tr("Willkommen bei refind"));
- ui->comboBoxDirectory->setCurrentText(
- startDir.isEmpty() ? QDir::currentPath() : startDir);
+ if (!startDir.isEmpty())
+ ui->comboBoxDirectory->setCurrentText(startDir);
+ if (ui->comboBoxDirectory->currentText().isEmpty())
+ ui->comboBoxDirectory->setCurrentText(QDir::currentPath());
statusBar()->addWidget(m_statusMessage);
connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search()));
connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search()));
connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
connect(ui->actionSelectDirectory, SIGNAL(triggered()), this,
SLOT(selectDirectory()));
+ connect(ui->actionSaveProgramState, SIGNAL(triggered()), this,
+ SLOT(saveState()));
connect(ui->pushButtonDirectory, SIGNAL(clicked()), this,
SLOT(selectDirectory()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
connect(ui->pushButtonExport, SIGNAL(clicked()), this, SLOT(exportFiles()));
connect(ui->pushButtonExportFile, SIGNAL(clicked()), this,
SLOT(selectExportFile()));
+ connect(ui->pushButtonFilePlaceholder, SIGNAL(clicked()), this,
+ SLOT(filePlaceholder()));
+ connect(ui->pushButtonHeaderPlaceholder, SIGNAL(clicked()), this,
+ SLOT(headerPlaceholder()));
+ connect(ui->pushButtonFooterPlaceholder, SIGNAL(clicked()), this,
+ SLOT(footerPlaceholder()));
m_horizontalHeader = ui->tableWidget->horizontalHeader();
connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ),
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
+/**
+ * initializeHomeializes the program home directory.
+ */
+void MainWindow::initializeHome(){
+ if (m_homeDir.isEmpty()){
+ m_homeDir = QDir::home().absoluteFilePath(".refind");
+ }
+
+ QDir home(m_homeDir);
+ if (!home.exists()){
+ if (!home.mkpath(m_homeDir)){
+ m_homeDir = home.tempPath() + "/.refind";
+ home.mkpath(m_homeDir);
+ }
+ }
+ if (!m_homeDir.endsWith("/"))
+ m_homeDir += "/";
+ m_storageFile = m_homeDir + "state.conf";
+ restoreState();
+}
+
/**
* Handles the event "header column clicked".
*
dialog.exec();
}
+/**
+ * Puts the absolute path of the current (selected) file into the clipboard.
+ */
+void MainWindow::absPathToClipboard(){
+ int row = ui->tableWidget->currentRow();
+ if (row >= 0){
+ QClipboard *clipboard = QApplication::clipboard();
+ clipboard->setText(buildAbsPath(row));
+ }
+}
+
+/**
+ * Puts the base directory into the clipboard.
+ */
+void MainWindow::baseDirToClipboard(){
+ QClipboard *clipboard = QApplication::clipboard();
+ clipboard->setText(m_lastBaseDir.absolutePath());
+}
+
/**
* Gets the absolute path of the file in the given row.
*
}
/**
- * Puts the absolute path of the current (selected) file into the clipboard.
+ * Converts the checkbox states to a filetype mask.
+ * @return the filetypes selected by the checkboxes
*/
-void MainWindow::absPathToClipboard(){
- int row = ui->tableWidget->currentRow();
- if (row >= 0){
- QClipboard *clipboard = QApplication::clipboard();
- clipboard->setText(buildAbsPath(row));
- }
+QDir::Filters MainWindow::buildFileTypes(){
+ QDir::Filters rc = 0;
+ if (ui->checkBoxDirs->isChecked())
+ rc |= QDir::Dirs;
+ if (ui->checkBoxFiles->isChecked())
+ rc |= QDir::Files;
+ if (rc == 0)
+ rc |= QDir::Dirs | QDir::Files;
+ if (!ui->checkBoxLinks->isChecked())
+ rc |= QDir::NoSymLinks;
+ if (ui->checkBoxHidden)
+ rc |= QDir::Hidden | QDir::System;
+ QDir::Filters mask = 0;
+ if (ui->checkBoxWritable->isChecked())
+ mask |= QDir::Writable;
+ if (ui->checkBoxReadable->isChecked())
+ mask |= QDir::Readable;
+ if (ui->checkBoxExecutable->isChecked())
+ mask |= QDir::Executable;
+ if (mask == 0)
+ mask |= QDir::PermissionMask;
+ rc |= mask;
+ return rc;
}
/**
- * Puts the base directory into the clipboard.
+ * Gets the content of the given cell as string.
+ *
+ * @param row the row number: 0..R-1
+ * @param col the column number: 0..C-1
+ * @return the text of the given cell
*/
-void MainWindow::baseDirToClipboard(){
- QClipboard *clipboard = QApplication::clipboard();
- clipboard->setText(m_lastBaseDir.absolutePath());
+QString MainWindow::cellAsText(int row, int col){
+ QTableWidgetItem* widget = ui->tableWidget->item(row, col);
+ QString rc;
+ if (widget != NULL)
+ rc = widget->text();
+ return rc;
}
/**
return rc;
}
+void MainWindow::closing(){
+ saveState();
+}
+
/**
- * Replaces placeholders valid in header and footer.
- *
- * @param text the text to convert
- * @return <code>text</code> with the esc sequences replaced
+ * Handles the click of the "export" button.
*/
-QString MainWindow::replaceGlobalPlaceholder(const QString& text){
- int start = 0;
- QString replacement;
- QString name;
- QString rc = text;
- while (start >= 0){
- start = rc.indexOf("${", start);
- if (start < 0)
- break;
- int end = rc.indexOf('}', start + 1);
- if (end < 0)
- break;
- name = rc.mid(start + 2, end - start - 2);
- if (name == "filepatterns")
- replacement = ui->comboBoxFilePatterns->currentText();
- else if (name == "base")
- replacement = m_lastBaseDir.absolutePath();
- else if (name == "textpattern")
- replacement = ui->comboBoxTextPattern->currentText();
- else if (name == "dirs")
- replacement = QString::number(m_statistics.m_dirs);
- else if (name == "files")
- replacement = QString::number(m_statistics.m_files);
- else if (name == "runtime")
- replacement = QString::number(m_statistics.m_runtimeSeconds, 'g', 3);
- else if (name == "bytes")
- replacement = QString::number(m_statistics.m_bytes);
- else if (name == "megabytes")
- replacement = QString::number((double) m_statistics.m_bytes / 1000000);
+void MainWindow::exportFiles(){
+ comboText(ui->comboBoxHeader);
+ comboText(ui->comboBoxTemplate);
+ comboText(ui->comboBoxExportFile);
+ comboText(ui->comboBoxFooter);
+ if (ui->radioButtonFile->isChecked()){
+ QString fn = ui->comboBoxExportFile->currentText();
+ FILE* fp = fopen(fn.toUtf8(), "w");
+ if (fp == NULL)
+ guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn);
else{
- QString msg = tr("unknown placeholder: ") + name;
- guiError(ui->comboBoxFooter, msg);
- break;
+ QTextStream stream(fp);
+ exportToStream(stream);
+ fclose(fp);
+ setStatusMessage(false, tr("result exported to ") + fn);
}
- rc = rc.replace("${" + name + "}", replacement);
- start += replacement.length();
+ }else{
+ QString value;
+ QTextStream stream(&value);
+ m_errors = 0;
+ exportToStream(stream);
+ QClipboard* clipboard = QApplication::clipboard();
+ clipboard->setText(value);
+ if (m_errors == 0)
+ setStatusMessage(false, tr("result exported to the clipboard"));
}
- return replaceEscSequences(rc);
}
/**
stream << replaceGlobalPlaceholder(ui->comboBoxHeader->currentText())
<< endl;
}
- int count = ui->tabWidget->count();
+ int count = ui->tableWidget->rowCount();
if (count > 0 && maxRow > 0)
count = maxRow;
for (int ii = 0; ii < count; ii++){
}
/**
- * Handles the click of the "export" button.
+ * Handles the push of "select file placeholder".
*/
-void MainWindow::exportFiles(){
- comboText(ui->comboBoxHeader);
- comboText(ui->comboBoxTemplate);
- comboText(ui->comboBoxExportFile);
- comboText(ui->comboBoxFooter);
- if (ui->radioButtonFile->isChecked()){
- QString fn = ui->comboBoxExportFile->currentText();
- FILE* fp = fopen(fn.toUtf8(), "w");
- if (fp == NULL)
- guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn);
- else{
- QTextStream stream(fp);
- exportToStream(stream);
- fclose(fp);
- setStatusMessage(false, tr("result exported to ") + fn);
- }
- }else{
- QString value;
- QTextStream stream(&value);
- m_errors = 0;
- exportToStream(stream);
- QClipboard* clipboard = QApplication::clipboard();
- clipboard->setText(value);
- if (m_errors == 0)
- setStatusMessage(false, tr("result exported to the clipboard"));
+void MainWindow::filePlaceholder(){
+ DialogFilePlaceholder dialog;
+ dialog.exec();
+ if (!dialog.var().isEmpty()){
+ QComboBox* target = ui->comboBoxTemplate;
+ target->setCurrentText(target->currentText() + dialog.var());
}
}
/**
- * Gets the content of the given cell as string.
- *
- * @param row the row number: 0..R-1
- * @param col the column number: 0..C-1
- * @return the text of the given cell
+ * Handles the push of "select placeholder for the footer".
*/
-QString MainWindow::cellAsText(int row, int col){
- QTableWidgetItem* widget = ui->tableWidget->item(row, col);
- QString rc;
- if (widget != NULL)
- rc = widget->text();
- return rc;
+void MainWindow::footerPlaceholder(){
+ handlePlaceholder(ui->comboBoxFooter);
}
/**
}
/**
- * Converts the checkbox states to a filetype mask.
- * @return the filetypes selected by the checkboxes
+ * Handles the global placeholder selection dialog.
+ *
+ * @param target OUT: the combobox where the result is appended
*/
-QDir::Filters MainWindow::buildFileTypes(){
- QDir::Filters rc = 0;
- if (ui->checkBoxDirs->isChecked())
- rc |= QDir::Dirs;
- if (ui->checkBoxFiles->isChecked())
- rc |= QDir::Files;
- if (rc == 0)
- rc |= QDir::Dirs | QDir::Files;
- if (!ui->checkBoxLinks->isChecked())
- rc |= QDir::NoSymLinks;
- if (ui->checkBoxHidden)
- rc |= QDir::Hidden | QDir::System;
- QDir::Filters mask = 0;
- if (ui->checkBoxWritable->isChecked())
- mask |= QDir::Writable;
- if (ui->checkBoxReadable->isChecked())
- mask |= QDir::Readable;
- if (ui->checkBoxExecutable->isChecked())
- mask |= QDir::Executable;
- if (mask == 0)
- mask |= QDir::PermissionMask;
- rc |= mask;
- return rc;
+void MainWindow::handlePlaceholder(QComboBox* target){
+ DialogGlobalPlaceholder dialog;
+ dialog.exec();
+ if (!dialog.var().isEmpty())
+ target->setCurrentText(target->currentText() + dialog.var());
+}
+
+/**
+ * Handles the push of "select placeholder for the header".
+ */
+void MainWindow::headerPlaceholder(){
+ handlePlaceholder(ui->comboBoxHeader);
}
/**
}
}
+/**
+ * Replaces placeholders valid in header and footer.
+ *
+ * @param text the text to convert
+ * @return <code>text</code> with the esc sequences replaced
+ */
+QString MainWindow::replaceGlobalPlaceholder(const QString& text){
+ int start = 0;
+ QString replacement;
+ QString name;
+ QString rc = text;
+ while (start >= 0){
+ start = rc.indexOf("${", start);
+ if (start < 0)
+ break;
+ int end = rc.indexOf('}', start + 1);
+ if (end < 0)
+ break;
+ name = rc.mid(start + 2, end - start - 2);
+ if (name == "filepatterns")
+ replacement = ui->comboBoxFilePatterns->currentText();
+ else if (name == "base")
+ replacement = m_lastBaseDir.absolutePath();
+ else if (name == "textpattern")
+ replacement = ui->comboBoxTextPattern->currentText();
+ else if (name == "dirs")
+ replacement = QString::number(m_statistics.m_dirs);
+ else if (name == "files")
+ replacement = QString::number(m_statistics.m_files);
+ else if (name == "runtime")
+ replacement = QString::number(m_statistics.m_runtimeSeconds, 'g', 3);
+ else if (name == "bytes")
+ replacement = QString::number(m_statistics.m_bytes);
+ else if (name == "megabytes")
+ replacement = QString::number((double) m_statistics.m_bytes / 1000000);
+ else if (name == "datetime")
+ replacement = QDateTime::currentDateTime().toLocalTime().toString(
+ "yyyy.MM.dd/hh:mm:ss");
+ else{
+ QString msg = tr("unknown placeholder: ") + name;
+ guiError(ui->comboBoxFooter, msg);
+ break;
+ }
+ rc = rc.replace("${" + name + "}", replacement);
+ start += replacement.length();
+ }
+ return replaceEscSequences(rc);
+}
+
+/**
+ * @brief Handles the action "reset parameters".
+ *
+ * Most of the filter parameters will be set to the default.
+ */
void MainWindow::resetParameters(){
ui->comboBoxFilePatterns->setCurrentText("");
ui->comboBoxMaxDepth->setCurrentText("");
ui->checkBoxExecutable->setChecked(true);
}
+/**
+ * Handles the push of the button "select directory".
+ */
+void MainWindow::restoreState(){
+ ReStateStorage storage(m_storageFile);
+ storage.setForm("main");
+ storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true);
+ storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true);
+ storage.restore(ui->comboBoxExportFile, "comboBoxExportFile", true);
+ storage.restore(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
+ storage.restore(ui->comboBoxFooter, "comboBoxFooter", true);
+ storage.restore(ui->comboBoxHeader, "comboBoxHeader", true);
+ storage.restore(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
+ storage.restore(ui->comboBoxMaxSize, "comboBoxMaxSize");
+ storage.restore(ui->comboBoxMinDepth, "comboBoxMinDepth");
+ storage.restore(ui->comboBoxMinSize, "comboBoxMinSize");
+ storage.restore(ui->comboBoxOlder, "comboBoxOlder");
+ storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true);
+ storage.restore(ui->comboBoxTextPattern, "comboBoxTextPattern");
+ storage.restore(ui->comboBoxYounger, "comboBoxYounger");
+ storage.close();
+}
+
+/**
+ * Handles the push of the button "select directory".
+ */
+void MainWindow::saveState(){
+ ReStateStorage storage(m_storageFile);
+ storage.setForm("main");
+ storage.store(ui->comboBoxDirectory, "comboBoxDirectory");
+ storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs");
+ storage.store(ui->comboBoxExportFile, "comboBoxExportFile");
+ storage.store(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
+ storage.store(ui->comboBoxFooter, "comboBoxFooter");
+ storage.store(ui->comboBoxHeader, "comboBoxHeader");
+ storage.store(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
+ storage.store(ui->comboBoxMaxSize, "comboBoxMaxSize");
+ storage.store(ui->comboBoxMinDepth, "comboBoxMinDepth");
+ storage.store(ui->comboBoxMinSize, "comboBoxMinSize");
+ storage.store(ui->comboBoxOlder, "comboBoxOlder");
+ storage.store(ui->comboBoxTemplate, "comboBoxTemplate");
+ storage.store(ui->comboBoxTextPattern, "comboBoxTextPattern");
+ storage.store(ui->comboBoxYounger, "comboBoxYounger");
+ storage.close();
+}
+
/**
* Handles the "search" button.
*/
* Calls the file selection dialog.
*/
void MainWindow::selectExportFile(){
- QString name = QFileDialog::getOpenFileName(this, tr("Select Export File"),
+ QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"),
ui->comboBoxExportFile->currentText());
if (!name.isEmpty())
ui->comboBoxExportFile->setCurrentText(name);
Q_OBJECT
public:
- explicit MainWindow(const QString& startDir, QWidget *parent = 0);
+ explicit MainWindow(const QString& startDir, const QString& homeDir,
+ QWidget *parent = 0);
~MainWindow();
private slots:
void about();
void absPathToClipboard();
void baseDirToClipboard();
+ void closing();
void exportFiles();
+ void filePlaceholder();
+ void footerPlaceholder();
void fullNameToClipboard();
void headerClicked(int col);
+ void headerPlaceholder();
void preview();
void resetParameters();
+ void saveState();
void search();
void selectDirectory();
void selectExportFile();
QDir::Filters buildFileTypes();
QString cellAsText(int row, int col);
void exportToStream(QTextStream& stream, int maxRow = -1);
+ void handlePlaceholder(QComboBox* target);
+ void initializeHome();
void prepareTextFind();
QString replaceGlobalPlaceholder(const QString& text);
+ void restoreState();
virtual void setStatusMessage(bool error, const QString& message);
private:
Ui::MainWindow *ui;
QHeaderView* m_horizontalHeader;
Qt::SortOrder m_lastOrder;
Statistics m_statistics;
+ QString m_homeDir;
+ QString m_storageFile;
};
#endif // MAINWINDOW_HPP
<string>Execute the search</string>
</property>
<property name="text">
- <string>&Search</string>
+ <string>&Run search</string>
</property>
<property name="icon">
<iconset>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
+ <property name="autoDefault">
+ <bool>true</bool>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item row="0" column="5">
<string>Select directory by a dialog box</string>
</property>
<property name="text">
- <string>...</string>
+ <string/>
</property>
<property name="icon">
<iconset resource="refind.qrc">
<item row="2" column="4" colspan="2">
<widget class="QPushButton" name="pushButtonSearch2">
<property name="text">
- <string>&Search</string>
+ <string>&Run search</string>
</property>
<property name="icon">
<iconset>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QComboBox" name="comboBoxTemplate">
+ <property name="toolTip">
+ <string>Template of a line for each file</string>
+ </property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="pushButtonPlaceholder">
+ <widget class="QPushButton" name="pushButtonFilePlaceholder">
<property name="maximumSize">
<size>
<width>50</width>
</size>
</property>
<property name="toolTip">
- <string>Placeholder for the template</string>
+ <string>Select a placeholder for the template</string>
</property>
<property name="text">
<string>...</string>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="comboBoxExportFile">
+ <property name="toolTip">
+ <string>Name of the export file</string>
+ </property>
<property name="editable">
<bool>true</bool>
</property>
</property>
<property name="maximumSize">
<size>
- <width>300</width>
+ <width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
- <string><html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li
-<li>\t tabulator</li>
-<li>\\ slash</li>
-</ul></p>
-</body></html></string>
+ <string>Text at the top of the export file</string>
</property>
<property name="editable">
<bool>true</bool>
<item row="1" column="3">
<widget class="QComboBox" name="comboBoxFooter">
<property name="toolTip">
- <string><html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li
-<li>\t tabulator</li>
-<li>\\ slash</li>
-</ul></p>
-</body></html></string>
+ <string>Text at the end of the export file</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
+ <item row="0" column="4">
+ <widget class="QPushButton" name="pushButtonHeaderPlaceholder">
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Select a placeholder for the header</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="4">
+ <widget class="QPushButton" name="pushButtonFooterPlaceholder">
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Select a placeholder for the footer</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
<addaction name="separator"/>
<addaction name="actionExport"/>
<addaction name="separator"/>
+ <addaction name="actionSaveProgramState"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
<addaction name="separator"/>
<bool>false</bool>
</attribute>
<addaction name="actionExport"/>
+ <addaction name="actionSaveProgramState"/>
<addaction name="actionExit"/>
</widget>
<action name="actionExit">
<normaloff>:/main/icons/action_go.png</normaloff>:/main/icons/action_go.png</iconset>
</property>
<property name="text">
- <string>&Search</string>
+ <string>&Run search</string>
</property>
<property name="toolTip">
<string>Search the files with the given properties</string>
</property>
<property name="shortcut">
- <string>Ctrl+F</string>
+ <string>Ctrl+R</string>
</property>
</action>
<action name="actionAbout">
<normalon>:/main/icons/table.gif</normalon>:/main/icons/table.png</iconset>
</property>
<property name="text">
- <string>Get &full name</string>
+ <string>&full name to clipboard</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
<normaloff>:/main/icons/action_paste.png</normaloff>:/main/icons/action_paste.png</iconset>
</property>
<property name="text">
- <string>Get &base directory</string>
+ <string>&base directory to clipboard</string>
</property>
<property name="toolTip">
<string>Puts the base directory into the clipboard</string>
<string>Sets the file filter properties to the default</string>
</property>
<property name="shortcut">
- <string>Ctrl+R</string>
+ <string>Ctrl+E</string>
+ </property>
+ </action>
+ <action name="actionSaveProgramState">
+ <property name="icon">
+ <iconset resource="refind.qrc">
+ <normaloff>:/main/icons/disk.png</normaloff>:/main/icons/disk.png</iconset>
+ </property>
+ <property name="text">
+ <string>Sa&ve</string>
+ </property>
+ <property name="toolTip">
+ <string>Saves the program state (position, history...) to a file</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
</property>
</action>
</widget>
<tabstop>comboBoxDirectory</tabstop>
<tabstop>pushButtonUp</tabstop>
<tabstop>pushButtonDirectory</tabstop>
+ <tabstop>pushButtonSearch</tabstop>
<tabstop>comboBoxFilePatterns</tabstop>
<tabstop>checkBoxFiles</tabstop>
<tabstop>checkBoxDirs</tabstop>
<tabstop>checkBoxLinks</tabstop>
<tabstop>checkBoxHidden</tabstop>
<tabstop>checkBoxWritable</tabstop>
+ <tabstop>checkBoxReadable</tabstop>
+ <tabstop>checkBoxExecutable</tabstop>
<tabstop>comboBoxTextPattern</tabstop>
<tabstop>checkBoxTextIgnoreCase</tabstop>
<tabstop>checkBoxRegExpr</tabstop>
<tabstop>checkBoxBinaryFiles</tabstop>
- <tabstop>pushButtonSearch</tabstop>
- <tabstop>tableWidget</tabstop>
<tabstop>comboBoxMinSize</tabstop>
<tabstop>comboBoxMaxSize</tabstop>
<tabstop>comboBoxYounger</tabstop>
<tabstop>comboBoxMinDepth</tabstop>
<tabstop>comboBoxMaxDepth</tabstop>
<tabstop>comboBoxExcludedDirs</tabstop>
+ <tabstop>pushButtonSearch2</tabstop>
+ <tabstop>comboBoxTemplate</tabstop>
+ <tabstop>pushButtonFilePlaceholder</tabstop>
+ <tabstop>comboBoxHeader</tabstop>
+ <tabstop>pushButtonHeaderPlaceholder</tabstop>
+ <tabstop>comboBoxExportFile</tabstop>
+ <tabstop>pushButtonExportFile</tabstop>
+ <tabstop>comboBoxFooter</tabstop>
+ <tabstop>pushButtonFooterPlaceholder</tabstop>
+ <tabstop>radioButtonFile</tabstop>
+ <tabstop>radioButtonClipboard</tabstop>
+ <tabstop>pushButtonExport</tabstop>
+ <tabstop>tabWidget</tabstop>
+ <tabstop>tableWidget</tabstop>
</tabstops>
<resources>
<include location="refind.qrc"/>
textfinder.cpp \
aboutdialog.cpp \
../../gui/ReStateStorage.cpp \
- ../../gui/ReGuiValidator.cpp
+ ../../gui/ReGuiValidator.cpp \
+ dialogglobalplaceholder.cpp \
+ dialogfileplaceholder.cpp
HEADERS += mainwindow.hpp \
../../gui/ReStateStorage.hpp \
aboutdialog.hpp \
../../gui/ReGuiValidator.hpp \
- ../../gui/regui.hpp
+ ../../gui/regui.hpp \
+ dialogglobalplaceholder.hpp \
+ dialogfileplaceholder.hpp
FORMS += mainwindow.ui \
- aboutdialog.ui
+ aboutdialog.ui \
+ dialogglobalplaceholder.ui \
+ dialogfileplaceholder.ui
RESOURCES += \
refind.qrc
#include "base/rebase.hpp"
#include <QtCore/qmath.h>
#include <QDateTime>
+
+/**
+ * Removes end of line characters if any.
+ *
+ * @param text text to inspect
+ * @return <code>text</code> without trailing '\n' and/or '\r'
+ */
+ReString ReQStringUtil::chomp(const ReString& text)
+{
+ int last = text.length() - 1;
+ while (last >= 0 && (text[last] == '\n' || text[last] == '\r')){
+ last--;
+ }
+ return last == text.length() - 1 ? text : text.mid(0, last + 1);
+}
+
+
/**
* @brief Determines the length and vlaue of an integer.
*
class ReQStringUtil {
public:
+ static ReString chomp(const ReString& text);
static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
NULL);
static int lengthOfDateTime(const ReString& text, int start = 0,
* Destructor.
*/
ReStateStorage::~ReStateStorage(){
+ close();
+}
+
+/**
+ * Closes open stream/file and frees the resources.
+ */
+void ReStateStorage::close(){
delete m_stream;
+ m_stream = NULL;
if (m_fp != NULL){
fclose(m_fp);
m_fp = NULL;
}
}
+/**
+ * Initializes the instance for writing the storage information.
+ */
+bool ReStateStorage::initForRead(){
+ if (m_fp == NULL)
+ m_fp = fopen(m_filename.toUtf8().constData(), "rb");
+ if (m_fp != NULL && m_stream == NULL){
+ m_stream = new QTextStream(m_fp, QIODevice::ReadOnly);
+ QString line;
+ m_map.clear();
+ QString value;
+ while (!m_stream->atEnd()){
+ line = m_stream->readLine(64 * 1024);
+ int ixAssignment = line.indexOf('=');
+ if (ixAssignment > 0){
+ value = line.mid(ixAssignment + 1);
+ QString key = line.mid(0, ixAssignment);
+ m_map.insert(key, value);
+ }
+ }
+ }
+ return m_stream != NULL;
+}
/**
* Initializes the instance for writing the storage information.
*/
if (m_fp == NULL)
m_fp = fopen(m_filename.toUtf8().constData(), "wb");
if (m_fp != NULL)
- m_stream = new QTextStream(m_fp, QIODevice::ReadOnly);
+ m_stream = new QTextStream(m_fp, QIODevice::ReadWrite);
return m_stream != NULL;
}
/**
return m_form;
}
+/**
+ * Returns the full name of a widget.
+ *
+ * @param name the name of the widget
+ * @return <form name> '.' <name> or <name> (if no form name is set)
+ */
+QString ReStateStorage::fullname(const QString& name){
+ return m_form.isEmpty() ? name : m_form + "." + name;
+}
/**
* Sets the name of the current form.
*
m_form = form;
}
+/**
+ * Restores the data of a combobox.
+ *
+ * @param combo the combobox to restore
+ * @param name the name of the combobox
+ * @param withCurrentText <code>true</code>: the current text will be set too
+ */
+void ReStateStorage::restore(QComboBox* combo, const QString& name,
+ bool withCurrentText){
+ if (initForRead()){
+ QString keyPrefix = fullname(name) + ".item";
+ int ix = 0;
+ QString key;
+ while (true){
+ key = keyPrefix + QString::number(ix);
+ if (!m_map.contains(key))
+ break;
+ combo->addItem(m_map.value(key));
+ ix++;
+ }
+ key = fullname(name) + ".text";
+ if (!withCurrentText)
+ combo->setCurrentText("");
+ else{
+ if (m_map.contains(key))
+ combo->setCurrentText(m_map.value(key));
+ }
+ }
+}
/**
* Stores the data of a combobox.
*
fullname = m_form + ".";
fullname += name;
for (int ii = 0; ii < combo->count(); ii++){
- *m_stream << fullname << ".item:" << ii << "=" << combo->itemText(ii)
+ *m_stream << fullname << ".item" << ii << "=" << combo->itemText(ii)
<< endl;
}
if (withCurrentText){
ReStateStorage(const QString& filename);
virtual ~ReStateStorage();
public:
+ void close();
QString form() const;
+ QString fullname(const QString& name);
+ bool initForRead();
bool initForWrite();
+ void restore(QComboBox* combo, const QString& name, bool withCurrentText =
+ false);
void store(const QComboBox* combo, const QString& name,
- bool withCurrentText = false);
+ bool withCurrentText = true);
void setForm(const QString& form);
private:
FILE* m_fp;
QTextStream* m_stream;
QString m_form;
+ QMap <QString, QString> m_map;
};
#endif /* GUI_RESTATESTORAGE_HPP_ */