SLOT(openLastFile()));
connect(ui->pushButtonOpenLastProject, SIGNAL(clicked()), this,
SLOT(openLastProject()));
+ Workspace* workspace = mainWindow->workspace();
+ buildTableInfo(workspace, Workspace::KEY_HISTORY_FILES, true, m_files);
+ buildTableInfo(workspace, Workspace::KEY_HISTORY_PROJECTS, false,
+ m_projects);
+ buildTable("", m_files, ui->tableWidgetFiles);
+ buildTable("", m_projects, ui->tableWidgetProjects);
+}
+/**
+ * Builds the table from the table using a filter expression.
+ *
+ * @param filter a filter expression with wildcards '*'
+ * @param lines the full table info
+ * @param table OUT: will be filled with all lines matching the filter
+ */
+void ProjectSelection::buildTable(const QString* filter, QStringList& lines,
+ QTableWidget* table) {
+ QStringList::const_iterator it;
+ for (it = lines.cbegin(); it != lines.cend(); ++it) {
+ bool matches = filter->isEmpty();
+ if (!matches) {
+ if (filter->startsWith("*")) {
+
+ } else {
+
+ }
+ }
+ if (matches) {
+ QStringList cols = it->split('\t');
+
+ }
+
+ }
+}
+
+/**
+ * Build the info for a table (last opened files or last opened projects).
+ *
+ * Note: the table shows a filtered part of this info.
+ *
+ * @param settings the history container
+ * @param key the name of the history entry
+ * @param withDate the file's name is part of the info
+ * @param tableContent OUT: the list containing the table info
+ */
+void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
+ bool withDate, QStringList& tableContent) {
+ settings->historyAsList(key, files);
+ QStringList::const_iterator it;
+ for (it = files.cbegin(); it != files.cend(); ++it) {
+ QFileInfo file(*it);
+ if (file.exists()) {
+ QString info = file.baseName();
+ if (withDate)
+ info.append("\t").append(
+ file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
+ info.append(file.dir());
+ }
+ }
}
/**
class TestReSettings: public ReTest {
public:
TestReSettings() :
- ReTest("ReSettings") {
+ ReTest("ReSettings") {
doIt();
}
public:
- void testAddHistoryEntry(){
+ void testAddHistoryEntry() {
QByteArray dir(ReFile::tempDir("resettings", NULL, false));
ReFile::deleteTree((QString) dir, false, &m_logger);
{
settings.historyAsList("digits", list);
checkEqu("1 2 3", list.join(' '));
}
- void setSettings(ReSettings& settings){
- settings.insertProperty(new ReProperty("level1.boolVal", "Boolean",
- "Boolean value for test", ReSettings::TRUE, PT_BOOL));
- settings.insertProperty(new ReProperty("level1.intVal", "Integer",
- "Integer value for test", "4711", PT_INT, "[0,9999]"));
- settings.insertProperty(new ReProperty("level2.strVal", "String",
- "String value for test", "crazy horse", PT_STRING));
-
+ void setSettings(ReSettings& settings) {
+ settings.insertProperty(
+ new ReProperty("level1.boolVal", "Boolean",
+ "Boolean value for test", ReSettings::TRUE, PT_BOOL));
+ settings.insertProperty(
+ new ReProperty("level1.intVal", "Integer", "Integer value for test",
+ "4711", PT_INT, "[0,9999]"));
+ settings.insertProperty(
+ new ReProperty("level2.strVal", "String", "String value for test",
+ "crazy horse", PT_STRING));
}
- void testBasic(){
+ void testBasic() {
QByteArray dir(ReFile::tempDir("resettings", NULL, false));
ReFile::deleteTree((QString) dir, false, &m_logger);
ReSettings settings(dir, "test", &m_memoryLogger);
setSettings(settings2);
settings2.changeValue("level1.boolVal", ReSettings::FALSE);
settings2.changeValue("level1.intVal", "1234");
- settings2.changeValue("level2.strVal", "pretty women");
+ settings2.changeValue("level2.strVal", "pretty woman");
settings2.writeSettings();
settings.readSettings();
* @param type the type of the property
* @param limits NULL or some rules for the property value
*/
-ReProperty::ReProperty(const char* name, const QString& title, const QString& description, const QString& defaultValue, RePropertyType type, const char* limits) :
- m_name(name),
- m_title(title),
- m_description(description),
- m_value(defaultValue),
- m_defaultValue(defaultValue),
- m_type(type),
- m_limits(limits) {
+ReProperty::ReProperty(const char* name, const QString& title,
+ const QString& description, const QString& defaultValue,
+ RePropertyType type, const char* limits) :
+ m_name(name),
+ m_title(title),
+ m_description(description),
+ m_value(defaultValue),
+ m_defaultValue(defaultValue),
+ m_type(type),
+ m_limits(limits) {
}
/**
* @param error OUT: NULL or the error message
* @return <code>true</code>: the value is allowed<br>
*/
-bool ReProperty::isValid(const QString& value, QString* error)
-{
+bool ReProperty::isValid(const QString& value, QString* error) {
bool rc = true;
if (error != NULL)
*error = "";
- if (m_limits != NULL){
- switch(m_type){
+ if (m_limits != NULL) {
+ switch (m_type) {
case PT_BOOL:
break;
- case PT_INT:
- {
+ case PT_INT: {
int nValue = value.toInt(&rc);
- if (! rc){
+ if (!rc) {
if (error != NULL)
*error = QObject::tr("not an integer: ") + value;
} else {
int minimum, maximum;
- if (sscanf(m_limits, "[%d,%d]", &minimum, &maximum) == 2)
- {
- if (nValue < minimum){
+ if (sscanf(m_limits, "[%d,%d]", &minimum, &maximum) == 2) {
+ if (nValue < minimum) {
rc = false;
if (error != NULL)
*error = value + " < " + minimum;
- } else if (nValue > maximum){
+ } else if (nValue > maximum) {
rc = false;
if (error != NULL)
*error = value + " < " + maximum;
* @param path the parent directory for the storage files
* @param prefix type of the storage: "proj" or "ws" (workspace)
*/
-ReSettings::ReSettings(const QString& path, const QString prefix, ReLogger* logger) :
- m_path(path),
- m_fileHistory(path + OS_SEPARATOR + prefix + ".history"),
- m_fileSettings(
- path + OS_SEPARATOR + prefix + ".settings"),
- m_settings(),
- m_chapters(),
- m_logger(logger) {
+ReSettings::ReSettings(const QString& path, const QString prefix,
+ ReLogger* logger) :
+ m_path(path),
+ m_fileHistory(path + OS_SEPARATOR + prefix + ".history"),
+ m_fileSettings(path + OS_SEPARATOR + prefix + ".settings"),
+ m_settings(),
+ m_chapters(),
+ m_logger(logger) {
}
* @param form the prefix of the key. If NULL the current form will be taken
*/
void ReSettings::addHistoryEntry(const char* key, const QString& value,
- char separator, int maxEntries) {
+ char separator, int maxEntries) {
ReStateStorage store(m_fileHistory);
+ store.initForRead();
store.addHistoryEntry(key, value, separator, maxEntries);
store.close();
store.flushMap();
ReProperty* property = m_settings.value(name, NULL);
if (property == NULL)
m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_1, "missing bool property %s",
- name);
+ name);
else if (property->m_type != PT_BOOL)
m_logger->logv(LOG_ERROR, LOC_BOOL_VALUE_2, "not a bool property %s",
- name);
+ name);
else
rc = !property->m_value.isEmpty();
return rc;
* @param name the name of the property
* @param value the new value
*/
-void ReSettings::changeValue(const char* name, const QString& value)
-{
+void ReSettings::changeValue(const char* name, const QString& value) {
QString error;
ReProperty* property = m_settings.value(name, NULL);
if (property == NULL)
m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_1, "unknown property: %s",
- name);
+ name);
else if (!property->isValid(value, &error))
- m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_2, "invalid value for %s: %s\n+++ %s",
- name, value.toUtf8().constData(),
- error.toUtf8().constData());
+ m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_2,
+ "invalid value for %s: %s\n+++ %s", name,
+ value.toUtf8().constData(), error.toUtf8().constData());
else
property->m_value = value;
}
* @return <code>list</code> (for chaining)
*/
QStringList&ReSettings::historyAsList(const char* key, QStringList& list,
- const char* form) {
+ const char* form) {
ReStateStorage store(m_fileHistory);
+ store.initForRead();
QStringList& rc = store.historyAsList(key, list, form);
store.close();
return rc;
ReProperty* property = m_settings.value(name, NULL);
if (property == NULL)
m_logger->logv(LOG_ERROR, LOC_INT_VALUE_1, "missing int property %s",
- name);
+ name);
else if (property->m_type != PT_INT)
m_logger->logv(LOG_ERROR, LOC_INT_VALUE_2, "not a int property %s",
- name);
+ name);
else
rc = property->m_value.toInt();
return rc;
/**
* Reads the configuration file.
*/
-void ReSettings::readSettings()
-{
+void ReSettings::readSettings() {
QFile file(m_fileSettings);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
- m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_1, "cannot open (%d): ",
- errno, m_fileSettings.toUtf8().constData());
- else{
+ m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_1, "cannot open (%d): ",
+ errno, m_fileSettings.toUtf8().constData());
+ else {
QTextStream input(&file);
int lineNo = 0;
while (!input.atEnd()) {
QString line = input.readLine();
int ix = line.indexOf('=');
if (ix < 0)
- m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_2, "missing '=': %s-%d: %s",
- m_fileSettings.toUtf8().constData(), lineNo,
- line.mid(0, 20).toUtf8().constData());
- else if (ix == 0 || ix == 1 && line.at(0) == '!')
- m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_3, "line starts with '=': %s-%d: %s",
- m_fileSettings.toUtf8().constData(), lineNo,
- line.mid(0, 20).toUtf8().constData());
+ m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_2,
+ "missing '=': %s-%d: %s",
+ m_fileSettings.toUtf8().constData(), lineNo,
+ line.mid(0, 20).toUtf8().constData());
+ else if (ix == 0 || (ix == 1 && line.at(0) == '!'))
+ m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_3,
+ "line starts with '=': %s-%d: %s",
+ m_fileSettings.toUtf8().constData(), lineNo,
+ line.mid(0, 20).toUtf8().constData());
else {
QByteArray name;
QString value;
- if (line.at(ix-1) == '!'){
+ if (line.at(ix - 1) == '!') {
name = line.left(ix - 1).toUtf8();
value = line.mid(ix + 1);
- value.replace("\\\\", "\01").replace("\\n", "\n")
- .replace("\\r", "\r").replace('\01', '\\');
+ value.replace("\\\\", "\01").replace("\\n", "\n").replace(
+ "\\r", "\r").replace('\01', '\\');
} else {
name = line.left(ix).toUtf8();
value = line.mid(ix + 1);
}
ReProperty* property = m_settings.value(name, NULL);
- if (property != NULL){
- switch(property->m_type){
+ if (property != NULL) {
+ switch (property->m_type) {
case PT_BOOL:
- property->m_value = value.isEmpty() ? ReSettings::FALSE
- : ReSettings::TRUE;
+ property->m_value =
+ value.isEmpty() ?
+ ReSettings::FALSE : ReSettings::TRUE;
break;
case PT_INT:
if (property->isValid(value))
ReProperty* property = m_settings.value(name, NULL);
if (property == NULL)
m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_1,
- "missing string property %s", name);
+ "missing string property %s", name);
else if (property->m_type != PT_STRING)
m_logger->logv(LOG_ERROR, LOC_STRING_VALUE_2,
- "not a string property %s", name);
+ "not a string property %s", name);
else
rc = property->m_value;
return rc;
/**
* Writes the values into the configuration file.
*/
-void ReSettings::writeSettings()
-{
+void ReSettings::writeSettings() {
QFile file(m_fileSettings);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
- m_logger->logv(LOG_ERROR, LOC_WRITE_SETTINGS_1, "cannot open (%d): ",
- errno, m_fileSettings.toUtf8().constData());
- else{
+ m_logger->logv(LOG_ERROR, LOC_WRITE_SETTINGS_1, "cannot open (%d): ",
+ errno, m_fileSettings.toUtf8().constData());
+ else {
QTextStream out(&file);
- QMap<const char*, ReProperty*>::const_iterator it;
- for (it = m_settings.cbegin(); it != m_settings.cend(); ++it){
+ QMap<QByteArray, ReProperty*>::const_iterator it;
+ for (it = m_settings.cbegin(); it != m_settings.cend(); ++it) {
ReProperty* property = it.value();
- if (property->m_value == property->m_defaultValue){
+ if (property->m_value == property->m_defaultValue) {
// we do not write the default value
} else if (it.value()->m_value.indexOf('\n') <= 0)
out << it.key() << "=" << it.value()->m_value << "\n";
- else{
+ else {
QString value = it.value()->m_value;
- out << it.key() << "!=" << value.replace("\\", "\\\\")
- .replace("\n", "\\n").replace("\r", "\\r") << "\n";
+ out << it.key() << "!="
+ << value.replace("\\", "\\\\").replace("\n", "\\n").replace(
+ "\r", "\\r") << "\n";
}
}
file.close();
}
}
-