summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Fultz <jfultz@wolfram.com>2015-08-09 05:13:19 -0500
committerJohn Fultz <jfultz@wolfram.com>2015-08-09 05:13:19 -0500
commitdc92d571f4f97f6420fdf1a94cc41c1d2808d71b (patch)
tree07bb60efdf4522296707285d22790251d74b3458
parentb8024ae268e49c17c40da105b9e22aaa41fcffeb (diff)
Progress on edit lexicon dialog.
* Files can now be loaded from user directory as well as app directory. * Edit lexicon dialog has been added, and pretty much all of the GUI elements framed out. Not actually implemented, yet. * Embiggen the board configuration dialog. * Some bits of code refactoring.
-rw-r--r--datamanager.cpp42
-rw-r--r--datamanager.h19
-rw-r--r--quacker/boardsetupdialog.cpp2
-rw-r--r--quacker/lexicondialog.cpp134
-rw-r--r--quacker/lexicondialog.h64
-rw-r--r--quacker/settings.cpp149
-rw-r--r--quacker/settings.h9
-rw-r--r--quackletest.cpp2
-rw-r--r--test/testharness.cpp2
9 files changed, 343 insertions, 80 deletions
diff --git a/datamanager.cpp b/datamanager.cpp
index e188668..eb65afd 100644
--- a/datamanager.cpp
+++ b/datamanager.cpp
@@ -41,7 +41,8 @@ DataManager::DataManager()
: m_evaluator(0), m_parameters(0), m_alphabetParameters(0), m_boardParameters(0), m_lexiconParameters(0), m_strategyParameters(0)
{
m_self = this;
- setDataDirectory(".");
+ setAppDataDirectory(".");
+ setUserDataDirectory(".");
seedRandomNumbers((int)time(NULL));
m_alphabetParameters = new EnglishAlphabetParameters;
@@ -122,6 +123,7 @@ void DataManager::cleanupComputerPlayers()
bool DataManager::fileExists(const string &filename)
{
+ // fixme: convert to wchar
struct stat buf;
int i = stat(filename.c_str(), &buf);
if (i == 0)
@@ -130,36 +132,38 @@ bool DataManager::fileExists(const string &filename)
return false;
}
-string DataManager::findDataFile(const string &subDirectory, const string &lexicon, string file)
+string DataManager::findDataFile(const string &subDirectory, const string &lexicon, const string &file)
{
- string firstTry = makeDataFilename(subDirectory, lexicon, file);
- if (fileExists(firstTry))
- return firstTry;
-
- string secondTry = makeDataFilename(subDirectory, m_backupLexicon, file);
- if (fileExists(secondTry))
- return secondTry;
+ string fname = makeDataFilename(subDirectory, lexicon, file, true);
+ if (!fileExists(fname))
+ fname = makeDataFilename(subDirectory, lexicon, file, false);
+ if (!fileExists(fname))
+ fname = makeDataFilename(subDirectory, m_backupLexicon, file, false);
+ if (!fileExists(fname))
+ fname = string();
- return string();
+ return fname;
}
-string DataManager::findDataFile(const string &subDirectory, string file)
+string DataManager::findDataFile(const string &subDirectory, const string &file)
{
- string firstTry = makeDataFilename(subDirectory, file);
- if (fileExists(firstTry))
- return firstTry;
+ string fname = makeDataFilename(subDirectory, file, true);
+ if (!fileExists(fname))
+ fname = makeDataFilename(subDirectory, file, false);
+ if (!fileExists(fname))
+ fname = string();
- return string();
+ return fname;
}
-string DataManager::makeDataFilename(const string &subDirectory, const string &lexicon, string file)
+string DataManager::makeDataFilename(const string &subDirectory, const string &lexicon, const string &file, bool user)
{
- return m_dataDirectory + "/" + subDirectory + "/" + lexicon + "/" + file;
+ return (user ? m_userDataDirectory : m_appDataDirectory) + "/" + subDirectory + "/" + lexicon + "/" + file;
}
-string DataManager::makeDataFilename(const string &subDirectory, string file)
+string DataManager::makeDataFilename(const string &subDirectory, const string &file, bool user)
{
- return m_dataDirectory + "/" + subDirectory + "/" + file;
+ return (user ? m_userDataDirectory : m_appDataDirectory) + "/" + subDirectory + "/" + file;
}
void DataManager::seedRandomNumbers(unsigned int seed)
diff --git a/datamanager.h b/datamanager.h
index 15e793a..196d525 100644
--- a/datamanager.h
+++ b/datamanager.h
@@ -99,21 +99,24 @@ public:
// Find a file at datadir/subdir/lexicon/file.
// If this doesn't exist, tries backupLexicon instead of lexicon.
// Returns empty string if the file is not found.
- string findDataFile(const string &subDirectory, const string &lexicon, string file);
+ string findDataFile(const string &subDirectory, const string &lexicon, const string &file);
// Find a file at datadir/subdir/file.
// Returns empty string if the file is not found.
- string findDataFile(const string &subDirectory, string file);
+ string findDataFile(const string &subDirectory, const string &file);
// returns similarly-named file
- string makeDataFilename(const string &subDirectory, const string &lexicon, string file);
- string makeDataFilename(const string &subDirectory, string file);
+ string makeDataFilename(const string &subDirectory, const string &lexicon, const string &file, bool user);
+ string makeDataFilename(const string &subDirectory, const string &file, bool user);
void setBackupLexicon(string backupLexicon) { m_backupLexicon = backupLexicon; }
string backupLexicon() { return m_backupLexicon; }
- void setDataDirectory(string directory) { m_dataDirectory = directory; }
- string dataDirectory() { return m_dataDirectory; }
+ void setAppDataDirectory(string directory) { m_appDataDirectory = directory; }
+ string appDataDirectory() { return m_appDataDirectory; }
+
+ void setUserDataDirectory(string directory) { m_userDataDirectory = directory; }
+ string userDataDirectory() { return m_userDataDirectory; }
void seedRandomNumbers(unsigned int seed);
int randomNumber();
@@ -123,7 +126,9 @@ private:
bool fileExists(const string &filename);
- string m_dataDirectory;
+ string m_appDataDirectory;
+
+ string m_userDataDirectory;
// lexicon that has all data files
string m_backupLexicon;
diff --git a/quacker/boardsetupdialog.cpp b/quacker/boardsetupdialog.cpp
index 379f79d..2bfd5ff 100644
--- a/quacker/boardsetupdialog.cpp
+++ b/quacker/boardsetupdialog.cpp
@@ -33,7 +33,7 @@
BoardSetupDialog::BoardSetupDialog(QWidget *parent) : QDialog(parent)
{
- resize(600,450);
+ resize(700,550);
setSizeGripEnabled(true);
// construct the board
diff --git a/quacker/lexicondialog.cpp b/quacker/lexicondialog.cpp
new file mode 100644
index 0000000..f812eed
--- /dev/null
+++ b/quacker/lexicondialog.cpp
@@ -0,0 +1,134 @@
+/*
+ * Quackle -- Crossword game artificial intelligence and analysis tool
+ * Copyright (C) 2005-2014 Jason Katz-Brown and John O'Laughlin.
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sstream>
+#include <QtGui>
+#include <datamanager.h>
+#include <quackleio/util.h>
+
+#include "lexicondialog.h"
+#include "customqsettings.h"
+#include "geometry.h"
+
+
+LexiconDialog::LexiconDialog(QWidget *parent, const QString &originalName) : QDialog(parent)
+{
+ m_originalName = originalName;
+
+ resize(450,350);
+
+ // construct the UI elements
+ m_lexiconName = new QLineEdit();
+ m_alphabetCombo = new QComboBox();
+
+ m_addWordsFromFile = new QPushButton(tr("Add words from &file..."));
+ m_clearAllWords = new QPushButton(tr("Clear &words and start again"));
+
+
+ m_lexiconInformation = new QLabel("");
+ m_lexiconInformation->setWordWrap(true);
+
+ m_saveChanges = new QPushButton(tr("&Save Changes"));
+ m_cancel = new QPushButton(tr("&Cancel"));
+ m_deleteLexicon = new QPushButton(tr("&Delete Lexicon"));
+
+ QLabel * lexiconNameLabel = new QLabel(tr("&Lexicon name:"));
+ QLabel * alphabetLabel = new QLabel(tr("&Alphabet:"));
+ lexiconNameLabel->setBuddy(m_lexiconName);
+ alphabetLabel->setBuddy(m_alphabetCombo);
+
+ QVBoxLayout * layout = new QVBoxLayout;
+ Geometry::setupFramedLayout(layout);
+ QHBoxLayout * lexiconRow = new QHBoxLayout;
+ Geometry::setupInnerLayout(lexiconRow);
+ QHBoxLayout * addRemoveWordsRow = new QHBoxLayout;
+ Geometry::setupInnerLayout(addRemoveWordsRow);
+ QHBoxLayout * buttonRow = new QHBoxLayout;
+ Geometry::setupInnerLayout(buttonRow);
+ QGroupBox * lexiconInformationGroup = new QGroupBox(tr("Lexicon information:"));
+ QVBoxLayout * lexiconInformationLayout = new QVBoxLayout(lexiconInformationGroup);
+
+ // build the layout
+ lexiconRow->addWidget(lexiconNameLabel);
+ lexiconRow->addWidget(m_lexiconName);
+ lexiconRow->addStretch();
+ lexiconRow->addWidget(alphabetLabel);
+ lexiconRow->addWidget(m_alphabetCombo);
+
+ addRemoveWordsRow->addWidget(m_addWordsFromFile);
+ addRemoveWordsRow->addWidget(m_clearAllWords);
+
+ lexiconInformationLayout->addWidget(m_lexiconInformation);
+
+ buttonRow->addWidget(m_deleteLexicon);
+ buttonRow->addStretch();
+ buttonRow->addWidget(m_cancel);
+ buttonRow->addWidget(m_saveChanges);
+
+ layout->addLayout(lexiconRow);
+ layout->addLayout(addRemoveWordsRow);
+ layout->addWidget(lexiconInformationGroup);
+ layout->addStretch();
+ layout->addLayout(buttonRow);
+
+ setLayout(layout);
+ m_saveChanges->setDefault(true);
+
+ // hook up signals and slots
+ // connect(m_lexiconName, SIGNAL(textEdited(const QString &)), this, SLOT(parametersChanged(const QString &)));
+ connect(m_addWordsFromFile, SIGNAL(clicked()), this, SLOT(addWordsFromFile()));
+ connect(m_saveChanges, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(m_cancel, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(m_deleteLexicon, SIGNAL(clicked()), this, SLOT(deleteLexicon()));
+
+ setWindowTitle(tr("Configure Lexicon - Quackle"));
+ updateLexiconInformation();
+
+ // sync game board with control states and draw board
+}
+
+LexiconDialog::~LexiconDialog()
+{
+
+}
+
+void LexiconDialog::deleteLexicon()
+{
+
+}
+
+void LexiconDialog::addWordsFromFile()
+{
+
+}
+
+void LexiconDialog::accept()
+{
+ QDialog::accept();
+}
+
+void LexiconDialog::updateLexiconInformation()
+{
+ QString text;
+ text.append(tr("File name:"));
+ text.append(tr("\n\nFile size:"));
+ text.append(tr("\n\nWord count:"));
+ text.append(tr("\n\nLexicon hash:"));
+
+ m_lexiconInformation->setText(text);
+}
diff --git a/quacker/lexicondialog.h b/quacker/lexicondialog.h
new file mode 100644
index 0000000..cdc0a59
--- /dev/null
+++ b/quacker/lexicondialog.h
@@ -0,0 +1,64 @@
+/*
+ * Quackle -- Crossword game artificial intelligence and analysis tool
+ * Copyright (C) 2005-2014 Jason Katz-Brown and John O'Laughlin.
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QUACKER_LEXICONDIALOG_H
+#define QUACKER_LEXICONDIALOG_H
+
+#include <string>
+#include <game.h>
+
+#include <QWidget>
+#include <QDialog>
+
+using namespace std;
+
+class QComboBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+
+class LexiconDialog : public QDialog
+{
+Q_OBJECT
+
+public:
+ LexiconDialog(QWidget *parent = 0, const QString &originalName = QString());
+ ~LexiconDialog();
+ virtual void accept();
+
+ void updateLexiconInformation();
+
+protected slots:
+ void deleteLexicon();
+ void addWordsFromFile();
+
+private:
+ QLineEdit *m_lexiconName;
+ QComboBox *m_alphabetCombo;
+ QPushButton *m_addWordsFromFile;
+ QPushButton *m_clearAllWords;
+ QLabel *m_lexiconInformation;
+
+ QPushButton *m_saveChanges;
+ QPushButton *m_cancel;
+ QPushButton *m_deleteLexicon;
+
+ QString m_originalName;
+};
+
+#endif
diff --git a/quacker/settings.cpp b/quacker/settings.cpp
index 15448f5..c516b91 100644
--- a/quacker/settings.cpp
+++ b/quacker/settings.cpp
@@ -45,6 +45,7 @@
#include "boardsetupdialog.h"
#include "customqsettings.h"
#include "graphicalboard.h"
+#include "lexicondialog.h"
Settings *Settings::m_self = 0;
Settings *Settings::self()
@@ -80,17 +81,18 @@ Settings::Settings(QWidget *parent)
#endif
if (QFile::exists("data"))
- m_dataDir = "data";
+ m_appDataDir = "data";
else if (QFile::exists("../data"))
- m_dataDir = "../data";
+ m_appDataDir = "../data";
else if (QFile::exists("Quackle.app/Contents/data"))
- m_dataDir = "Quackle.app/Contents/data";
+ m_appDataDir = "Quackle.app/Contents/data";
else
{
if (!directory.cd("data") || !directory.cd("../data"))
QMessageBox::critical(0, tr("Error Initializing Data Files - Quacker"), tr("<p>Could not open data directory. Quackle will be useless. Try running the quacker executable with quackle/quacker/ as the current directory.</p>"));
- m_dataDir = directory.absolutePath();
+ m_appDataDir = directory.absolutePath();
}
+ m_userDataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
}
void Settings::createGUI()
@@ -98,86 +100,69 @@ void Settings::createGUI()
if (m_lexiconNameCombo != 0)
return;
- QVBoxLayout *vlayout = new QVBoxLayout(this);
+ QGridLayout *layout = new QGridLayout(this);
m_lexiconNameCombo = new QComboBox;
connect(m_lexiconNameCombo, SIGNAL(activated(const QString &)), this, SLOT(lexiconChanged(const QString &)));
- QStringList lexiconItems;
- populateListFromFilenames(lexiconItems, "lexica");
- m_lexiconNameCombo->addItems(lexiconItems);
+ populateComboFromFilenames(m_lexiconNameCombo, "lexica", "lexicon");
- QHBoxLayout *lexiconLayout = new QHBoxLayout;
QLabel *lexiconNameLabel = new QLabel(tr("&Lexicon:"));
lexiconNameLabel->setBuddy(m_lexiconNameCombo);
m_editLexicon = new QPushButton(tr("Edit..."));
m_editLexicon->setMaximumWidth(60);
connect(m_editLexicon, SIGNAL(clicked()), this, SLOT(editLexicon()));
- lexiconLayout->addWidget(lexiconNameLabel);
- lexiconLayout->addWidget(m_lexiconNameCombo);
- lexiconLayout->addWidget(m_editLexicon);
-
m_alphabetNameCombo = new QComboBox;
connect(m_alphabetNameCombo, SIGNAL(activated(const QString &)), this, SLOT(alphabetChanged(const QString &)));
- QStringList alphabetItems;
- populateListFromFilenames(alphabetItems, "alphabets");
- m_alphabetNameCombo->addItems(alphabetItems);
+ populateComboFromFilenames(m_alphabetNameCombo, "alphabets", "");
- QHBoxLayout *alphabetLayout = new QHBoxLayout;
QLabel *alphabetNameLabel = new QLabel(tr("&Alphabet:"));
alphabetNameLabel->setBuddy(m_alphabetNameCombo);
m_editAlphabet = new QPushButton(tr("Edit..."));
m_editAlphabet->setMaximumWidth(60);
connect(m_editAlphabet, SIGNAL(clicked()), this, SLOT(editAlphabet()));
- alphabetLayout->addWidget(alphabetNameLabel);
- alphabetLayout->addWidget(m_alphabetNameCombo);
- alphabetLayout->addWidget(m_editAlphabet);
-
m_themeNameCombo = new QComboBox;
connect(m_themeNameCombo, SIGNAL(activated(const QString &)), this, SLOT(themeChanged(const QString &)));
- QStringList themeItems;
- populateListFromFilenames(themeItems, "themes");
- m_themeNameCombo->addItems(themeItems);
+ populateComboFromFilenames(m_themeNameCombo, "themes", "");
- QHBoxLayout *themeLayout = new QHBoxLayout;
QLabel *themeNameLabel = new QLabel(tr("&Theme:"));
themeNameLabel->setBuddy(m_themeNameCombo);
m_editTheme = new QPushButton(tr("Edit..."));
m_editTheme->setMaximumWidth(60);
connect(m_editTheme, SIGNAL(clicked()), this, SLOT(editTheme()));
- themeLayout->addWidget(themeNameLabel);
- themeLayout->addWidget(m_themeNameCombo);
- themeLayout->addWidget(m_editTheme);
-
m_boardNameCombo = new QComboBox;
connect(m_boardNameCombo, SIGNAL(activated(const QString &)), this, SLOT(boardChanged(const QString &)));
- QStringList boardItems;
- populateListFromFilenames(boardItems, "boards");
- m_boardNameCombo->addItems(boardItems);
- m_boardNameCombo->addItem(tr("Add new board..."));
+ populateComboFromFilenames(m_boardNameCombo, "boards", "board");
- QHBoxLayout *boardLayout = new QHBoxLayout;
QLabel *boardNameLabel = new QLabel(tr("&Board:"));
boardNameLabel->setBuddy(m_boardNameCombo);
m_editBoard = new QPushButton(tr("Edit..."));
m_editBoard->setMaximumWidth(60);
connect(m_editBoard, SIGNAL(clicked()), this, SLOT(editBoard()));
- boardLayout->addWidget(boardNameLabel);
- boardLayout->addWidget(m_boardNameCombo);
- boardLayout->addWidget(m_editBoard);
-
- vlayout->addLayout(lexiconLayout);
- vlayout->addLayout(alphabetLayout);
- vlayout->addLayout(themeLayout);
- vlayout->addLayout(boardLayout);
- vlayout->addStretch();
+ layout->addWidget(lexiconNameLabel, 0, 0, Qt::AlignRight);
+ layout->addWidget(m_lexiconNameCombo, 0, 1);
+ layout->addWidget(m_editLexicon, 0, 2);
+ layout->addWidget(alphabetNameLabel, 1, 0, Qt::AlignRight);
+ layout->addWidget(m_alphabetNameCombo, 1, 1);
+ // layout->addWidget(m_editAlphabet, 1, 2);
+ layout->addWidget(themeNameLabel, 2, 0, Qt::AlignRight);
+ layout->addWidget(m_themeNameCombo, 2, 1);
+ // layout->addWidget(m_editTheme, 2, 2);
+ layout->addWidget(boardNameLabel, 3, 0, Qt::AlignRight);
+ layout->addWidget(m_boardNameCombo, 3, 1);
+ layout->addWidget(m_editBoard, 3, 2);
+
+ layout->setColumnMinimumWidth(3, 0);
+ layout->setColumnStretch(3, 1);
+ layout->setRowMinimumHeight(4, 0);
+ layout->setRowStretch(4, 1);
load();
}
@@ -201,7 +186,8 @@ void Settings::initialize()
CustomQSettings settings;
QUACKLE_DATAMANAGER->setBackupLexicon("twl06");
- QUACKLE_DATAMANAGER->setDataDirectory(m_dataDir.toStdString());
+ QUACKLE_DATAMANAGER->setAppDataDirectory(m_appDataDir.toStdString());
+ QUACKLE_DATAMANAGER->setUserDataDirectory(m_userDataDir.toStdString());
QString lexiconName = settings.value("quackle/settings/lexicon-name", QString("twl06")).toString();
@@ -272,11 +258,13 @@ void Settings::setQuackleToUseAlphabetName(const string &alphabetName)
void Settings::setQuackleToUseThemeName(const QString &themeName)
{
m_themeName = themeName;
- QString themeFile = m_dataDir + "/themes/" + themeName + ".ini";
+ QString themeFile = m_userDataDir + "/themes/" + themeName + ".ini";
+ if (!QFile::exists(themeFile))
+ themeFile = m_appDataDir + "/themes/" + themeName + ".ini";
if (!QFile::exists(themeFile))
{
m_themeName = "traditional";
- themeFile = m_dataDir + "/themes/traditional.ini";
+ themeFile = m_appDataDir + "/themes/traditional.ini";
}
PixmapCacher::self()->readTheme(themeFile);
}
@@ -303,6 +291,11 @@ void Settings::setQuackleToUseBoardName(const QString &boardName)
void Settings::lexiconChanged(const QString &lexiconName)
{
+ if (m_lexiconNameCombo->currentIndex() == m_lexiconNameCombo->count() - 1)
+ {
+ editLexicon();
+ return;
+ }
string lexiconNameString = QuackleIO::Util::qstringToStdString(lexiconName);
setQuackleToUseLexiconName(lexiconNameString);
@@ -314,6 +307,11 @@ void Settings::lexiconChanged(const QString &lexiconName)
void Settings::alphabetChanged(const QString &alphabetName)
{
+ if (m_alphabetNameCombo->currentIndex() == m_alphabetNameCombo->count() - 1)
+ {
+ editAlphabet();
+ return;
+ }
string alphabetNameString = QuackleIO::Util::qstringToStdString(alphabetName);
setQuackleToUseAlphabetName(alphabetNameString);
@@ -325,6 +323,11 @@ void Settings::alphabetChanged(const QString &alphabetName)
void Settings::themeChanged(const QString &themeName)
{
+ if (m_themeNameCombo->currentIndex() == m_themeNameCombo->count() - 1)
+ {
+ editTheme();
+ return;
+ }
setQuackleToUseThemeName(themeName);
CustomQSettings settings;
@@ -427,18 +430,62 @@ void Settings::loadBoardNameCombo()
m_boardNameCombo->setCurrentIndex(currentItemIndex);
}
-void Settings::populateListFromFilenames(QStringList& list, const QString &path)
+void Settings::editLexicon()
+{
+ QString name = m_lexiconNameCombo->currentText();
+ if (m_lexiconNameCombo->currentIndex() == m_lexiconNameCombo->count() - 1)
+ name = "";
+ LexiconDialog dialog(this, name);
+ if (dialog.exec())
+ {
+ populateComboFromFilenames(m_lexiconNameCombo, "lexica", "lexicon");
+ load();
+ }
+}
+
+void Settings::editAlphabet()
+{
+#if 0
+ QString name = m_alphabetNameCombo->currentText();
+ if (m_alphabetNameCombo->currentIndex() == m_alphabetNameCombo->count() - 1)
+ name = "";
+ AlphabetDialog dialog(this);
+ if (dialog.exec())
+ {
+ populateComboFromFilenames(m_alphabetNameCombo, "alphabets", "alphabet");
+ load();
+ }
+#endif // 0
+}
+
+void Settings::editTheme()
+{
+#if 0
+ QString name = m_themeNameCombo->currentText();
+ if (m_themeNameCombo->currentIndex() == m_themeNameCombo->count() - 1)
+ name = "";
+ ThemeDialog dialog(this);
+ if (dialog.exec())
+ {
+ populateThemeFromFilenames(m_themeNameCombo, "themes", "theme");
+ load();
+ }
+#endif // 0
+}
+
+void Settings::populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &label)
{
QStringList fileList;
- QDir dir(m_dataDir);
+ QDir dir(m_appDataDir);
if (dir.cd(path))
fileList << dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
- dir = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
+ dir = QDir(m_userDataDir);
if (dir.cd(path))
fileList << dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
QStringListIterator i(fileList);
QString fileName;
+ QStringList list;
int periodPos;
while (i.hasNext())
@@ -452,4 +499,8 @@ void Settings::populateListFromFilenames(QStringList& list, const QString &path)
}
}
list.removeDuplicates();
+
+ combo->addItems(list);
+ if (label.size() > 0)
+ combo->addItem(QString(tr("Add new ")).append(path).append("..."));
}
diff --git a/quacker/settings.h b/quacker/settings.h
index bc0e8fa..ee1b59a 100644
--- a/quacker/settings.h
+++ b/quacker/settings.h
@@ -65,6 +65,10 @@ protected slots:
void addBoard();
void editBoard();
+ void editLexicon();
+ void editAlphabet();
+ void editTheme();
+
void setQuackleToUseLexiconName(const string &lexiconName);
void setQuackleToUseAlphabetName(const string &alphabetName);
void setQuackleToUseThemeName(const QString &themeName);
@@ -79,7 +83,8 @@ protected:
QPushButton *m_editAlphabet;
QPushButton *m_editTheme;
QPushButton *m_editBoard;
- QString m_dataDir;
+ QString m_appDataDir;
+ QString m_userDataDir;
QString m_themeName;
private:
@@ -87,7 +92,7 @@ private:
void loadBoardNameCombo();
// load up an item list based on a list of filenames
- void populateListFromFilenames(QStringList& list, const QString &path);
+ void populateComboFromFilenames(QComboBox* combo, const QString &path, const QString &label);
static Settings *m_self;
};
diff --git a/quackletest.cpp b/quackletest.cpp
index 5f3066c..e69c2cb 100644
--- a/quackletest.cpp
+++ b/quackletest.cpp
@@ -45,7 +45,7 @@ int main()
{
Quackle::DataManager dataManager;
- dataManager.setDataDirectory("data");
+ dataManager.setAppDataDirectory("data");
dataManager.lexiconParameters()->loadDawg(Quackle::LexiconParameters::findDictionaryFile("twl06.dawg"));
dataManager.lexiconParameters()->loadGaddag(Quackle::LexiconParameters::findDictionaryFile("twl06.gaddag"));
dataManager.strategyParameters()->initialize("twl06");
diff --git a/test/testharness.cpp b/test/testharness.cpp
index 64847d1..683443f 100644
--- a/test/testharness.cpp
+++ b/test/testharness.cpp
@@ -191,7 +191,7 @@ void TestHarness::startUp()
UVcout << "Starting up.";
m_dataManager.setBackupLexicon("twl06");
- m_dataManager.setDataDirectory("../data");
+ m_dataManager.setAppDataDirectory("../data");
QString alphabetFile = QuackleIO::Util::stdStringToQString(Quackle::AlphabetParameters::findAlphabetFile(QuackleIO::Util::qstringToStdString(m_alphabet) + ".quackle_alphabet"));
QuackleIO::FlexibleAlphabetParameters *flexure = new QuackleIO::FlexibleAlphabetParameters;