Added Warnings and settings information
diff --git a/gui/ChronoShareGui.pro.user b/gui/ChronoShareGui.pro.user
index 30d20df..a40f863 100644
--- a/gui/ChronoShareGui.pro.user
+++ b/gui/ChronoShareGui.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.6.0, 2013-01-17T23:46:43. -->
+<!-- Written by Qt Creator 2.6.0, 2013-01-18T00:57:47. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
diff --git a/gui/chronosharegui.cpp b/gui/chronosharegui.cpp
index 0285f78..6faa80b 100644
--- a/gui/chronosharegui.cpp
+++ b/gui/chronosharegui.cpp
@@ -23,10 +23,15 @@
ChronoShareGui::ChronoShareGui(QWidget *parent) :
QWidget(parent),
- m_fileDialogWidget(new QWidget())
+ m_settingsFilePath(QDir::homePath() + ".cronoShare")
{
// load settings
- loadSettings();
+ if(!loadSettings())
+ {
+ // prompt user to choose folder
+ openMessageBox("First Time Setup", "Please select your shared folder location.");
+ openFileDialog();
+ }
// create actions that result from clicking a menu option
createActions();
@@ -47,9 +52,32 @@
delete m_trayIcon;
delete m_trayIconMenu;
delete m_openFolder;
+ delete m_viewSettings;
delete m_changeFolder;
delete m_quitProgram;
- delete m_fileDialogWidget;
+}
+
+void ChronoShareGui::openMessageBox(QString title, QString text)
+{
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(title);
+ messageBox.setText(text);
+
+ messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
+
+ messageBox.exec();
+}
+
+void ChronoShareGui::openMessageBox(QString title, QString text, QString infotext)
+{
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(title);
+ messageBox.setText(text);
+ messageBox.setInformativeText(infotext);
+
+ messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
+
+ messageBox.exec();
}
void ChronoShareGui::createActions()
@@ -58,6 +86,10 @@
m_openFolder = new QAction(tr("&Open Folder"), this);
connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder()));
+ // create the "view settings" action
+ m_viewSettings = new QAction(tr("&View Settings"), this);
+ connect(m_viewSettings, SIGNAL(triggered()), this, SLOT(viewSettings()));
+
// create the "change folder" action
m_changeFolder = new QAction(tr("&Change Folder"), this);
connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog()));
@@ -75,6 +107,8 @@
// add actions to the menu
m_trayIconMenu->addAction(m_openFolder);
+ m_trayIconMenu->addSeparator();
+ m_trayIconMenu->addAction(m_viewSettings);
m_trayIconMenu->addAction(m_changeFolder);
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_quitProgram);
@@ -120,11 +154,18 @@
void ChronoShareGui::openFileDialog()
{
// prompt user for new directory
- m_dirPath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
+ QString tempPath = QFileDialog::getExistingDirectory(this, tr("Choose a new folder"),
m_dirPath, QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks);
+ QFileInfo qFileInfo(tempPath);
+
+ if(qFileInfo.isDir())
+ m_dirPath = tempPath;
+ else
+ openMessageBox("Error", "Not a valid folder, Ignoring.");
qDebug() << m_dirPath;
+ openMessageBox("Current Folder", "Current Shared Folder:\n" + m_dirPath, "You may change the folder by selecting \"change folder\" from the icon in the system tray.");
// save settings
saveSettings();
@@ -139,11 +180,30 @@
}
}
-void ChronoShareGui::loadSettings()
+void ChronoShareGui::viewSettings()
{
+ // simple for now
+ openMessageBox("Chronoshare Settings", "CurrentFolder:\n" + m_dirPath);
+}
+
+bool ChronoShareGui::loadSettings()
+{
+ bool successful = false;
+
// Load Settings
QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
- m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
+ if(settings.contains("dirPath"))
+ {
+ m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
+ successful = true;
+ }
+ else
+ {
+ m_dirPath = QDir::homePath();
+ successful = false;
+ }
+
+ return successful;
}
void ChronoShareGui::saveSettings()
diff --git a/gui/chronosharegui.h b/gui/chronosharegui.h
index c1ae9b2..48e2bc3 100644
--- a/gui/chronosharegui.h
+++ b/gui/chronosharegui.h
@@ -30,6 +30,7 @@
#include <QDir>
#include <QFileDialog>
#include <QCloseEvent>
+#include <QMessageBox>
class ChronoShareGui : public QWidget
{
@@ -52,6 +53,9 @@
// handle left click of tray icon
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
+ // view chronoshare settings
+ void viewSettings();
+
private:
// create actions that result from clicking a menu option
void createActions();
@@ -63,11 +67,17 @@
void setIcon();
// load persistent settings
- void loadSettings();
+ bool loadSettings();
// save persistent settings
void saveSettings();
+ // prompt user dialog box
+ void openMessageBox(QString title, QString text);
+
+ // overload
+ void openMessageBox(QString title, QString text, QString infotext);
+
// capture close event
void closeEvent(QCloseEvent* event);
@@ -76,14 +86,13 @@
QMenu* m_trayIconMenu; // tray icon menu
QAction* m_openFolder; // open the shared folder action
+ QAction* m_viewSettings; // chronoShare settings
QAction* m_changeFolder; // change the shared folder action
QAction* m_quitProgram; // quit program action
QString m_dirPath; // shared directory
QString m_settingsFilePath; // settings file path
-
- QWidget* m_fileDialogWidget; // file dialog widget
};
#endif // CHRONOSHAREGUI_H