#include "settingscontroller.h"
#include "data/settings.h"
+#include "ui/mainwindow.h"
+#include "ui/optionsdialog.h"
#include <QFile>
#include <QXmlStreamReader>
#include <QDir>
#include <iostream>
-SettingsController::SettingsController(Settings *settings)
- : _settings(settings)
+SettingsController::SettingsController(MainWindow *main_window, Settings *settings)
+ : _main_window(main_window),
+ _settings(settings)
{
}
STATE_PREVIOUS_LOCATION_NAME,
STATE_GPS,
STATE_SEARCH,
+ STATE_ORIENTATION
};
void SettingsController::Load()
state = STATE_GPS;
} else if (state == STATE_SETTINGS && xml.name() == "search") {
state = STATE_SEARCH;
+ } else if (state == STATE_SETTINGS && xml.name() == "orientation") {
+ state = STATE_ORIENTATION;
} else {
state = STATE_DOCUMENT;
}
} else if (token == QXmlStreamReader::EndElement) {
- if (state == STATE_SEARCH) {
+ if (state == STATE_ORIENTATION) {
+ state = STATE_SETTINGS;
+ } else if (state == STATE_SEARCH) {
state = STATE_SETTINGS;
} else if (state == STATE_GPS) {
state = STATE_SETTINGS;
} else if (xml.text() == "movies") {
_settings->SetSearchObjectsType(Settings::MOVIES);
}
+ } else if (state == STATE_ORIENTATION) {
+ if (xml.text() == "landscape") {
+ _settings->SetOrientationMode(Settings::LANDSCAPE);
+ } else if (xml.text() == "portrait") {
+ _settings->SetOrientationMode(Settings::PORTRAIT);
+ } else if (xml.text() == "autorotation") {
+ _settings->SetOrientationMode(Settings::AUTOROTATION);
+ }
}
}
}
xml.writeStartElement("settings");
xml.writeStartElement("location");
xml.writeTextElement("name", _settings->GetLocation().GetLocationName());
- xml.writeEndElement();
+ xml.writeEndElement(); // </location>
xml.writeStartElement("previous-locations");
Q_FOREACH(Location location, _settings->GetPreviousLocations()) {
xml.writeStartElement("location");
xml.writeTextElement("name", location.GetLocationName());
xml.writeEndElement();
}
- xml.writeEndElement();
+ xml.writeEndElement(); // </previous-locations>
QString v;
xml.writeStartElement("gps");
xml.writeAttribute("enabled", _settings->IsGPSEnabled() ? "yes" : "no");
- xml.writeEndElement();
+ xml.writeEndElement(); // </gps>
switch (_settings->GetSearchObjectsType()) {
case Settings::THEATERS:
v = "theaters";
break;
}
xml.writeTextElement("search", v);
- xml.writeEndElement();
+ switch (_settings->GetOrientationMode()) {
+ case Settings::LANDSCAPE:
+ v = "landscape";
+ break;
+ case Settings::PORTRAIT:
+ v = "portrait";
+ break;
+ case Settings::AUTOROTATION:
+ v = "autorotation";
+ break;
+ }
+ xml.writeTextElement("orientation", v);
+ xml.writeEndElement(); // </settings>
xml.writeEndDocument();
} else {
// TODO error message unable to create file
}
}
+void SettingsController::EmitInitialSettings()
+{
+ emit SettingsChanged(*_settings);
+}
+
+void SettingsController::OpenSettingsDialog()
+{
+#ifdef Q_WS_MAEMO_5
+ OptionsDialog *dialog = new OptionsDialog(_main_window);
+ connect(dialog, SIGNAL(Accept(Settings)), this, SLOT(AcceptSettingsDialog(Settings)));
+ connect(dialog, SIGNAL(Cancel(Settings)), this, SLOT(CancelSettingsDialog(Settings)));
+ dialog->SetSettings(*_settings);
+ dialog->show();
+ // dialog deletes itself
+#endif
+}
+
+void SettingsController::AcceptSettingsDialog(const Settings &settings)
+{
+ *_settings = settings;
+ emit SettingsChanged(settings);
+}
+
+void SettingsController::CancelSettingsDialog(const Settings &settings)
+{
+ Q_UNUSED(settings);
+ // do nothing
+}
+
QString SettingsController::GetSettingsFileName()
{
QString dirpath = QDir::homePath() + "/.movie-schedule";