Update of gui. Now it builds and .app bundle, which doesn't show icon in the dock bar
diff --git a/gui/chronosharegui.cpp b/gui/chronosharegui.cpp
index 5b49909..8f46363 100644
--- a/gui/chronosharegui.cpp
+++ b/gui/chronosharegui.cpp
@@ -19,213 +19,218 @@
*/
#include "chronosharegui.h"
+#include "logging.h"
-ChronoShareGui::ChronoShareGui(QWidget *parent) :
- QWidget(parent),
- m_settingsFilePath(QDir::homePath() + "/.cronoshare")
+INIT_LOGGER ("Gui");
+
+ChronoShareGui::ChronoShareGui(QWidget *parent)
+ : QWidget(parent)
+ // , m_settingsFilePath(QDir::homePath() + "/.chronoshare")
{
- // load settings
- if(!loadSettings())
+ // load settings
+ if(!loadSettings())
{
- // prompt user to choose folder
- openMessageBox("First Time Setup", "Please select your shared folder location.");
- openFileDialog();
+ // 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();
+ // create actions that result from clicking a menu option
+ createActions();
- // create tray icon
- createTrayIcon();
+ // create tray icon
+ createTrayIcon();
- // set icon image
- setIcon();
+ // set icon image
+ setIcon();
- // show tray icon
- m_trayIcon->show();
+ // show tray icon
+ m_trayIcon->show();
}
ChronoShareGui::~ChronoShareGui()
{
- // cleanup
- delete m_trayIcon;
- delete m_trayIconMenu;
- delete m_openFolder;
- delete m_viewSettings;
- delete m_changeFolder;
- delete m_quitProgram;
+ // cleanup
+ delete m_trayIcon;
+ delete m_trayIconMenu;
+ delete m_openFolder;
+ delete m_viewSettings;
+ delete m_changeFolder;
+ delete m_quitProgram;
}
void ChronoShareGui::openMessageBox(QString title, QString text)
{
- QMessageBox messageBox(this);
- messageBox.setWindowTitle(title);
- messageBox.setText(text);
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(title);
+ messageBox.setText(text);
- messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
+ messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
- messageBox.exec();
+ messageBox.exec();
}
void ChronoShareGui::openMessageBox(QString title, QString text, QString infotext)
{
- QMessageBox messageBox(this);
- messageBox.setWindowTitle(title);
- messageBox.setText(text);
- messageBox.setInformativeText(infotext);
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(title);
+ messageBox.setText(text);
+ messageBox.setInformativeText(infotext);
- messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
+ messageBox.setIconPixmap(QPixmap(":/images/friends-group-icon.png"));
- messageBox.exec();
+ messageBox.exec();
}
void ChronoShareGui::createActions()
{
- // create the "open folder" action
- m_openFolder = new QAction(tr("&Open Folder"), this);
- connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder()));
+ // create the "open folder" action
+ 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 "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()));
+ // create the "change folder" action
+ m_changeFolder = new QAction(tr("&Change Folder"), this);
+ connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog()));
- // create the "quit program" action
- m_quitProgram = new QAction(tr("&Quit"), this);
- connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit()));
+ // create the "quit program" action
+ m_quitProgram = new QAction(tr("&Quit"), this);
+ connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void ChronoShareGui::createTrayIcon()
{
- // create a new icon menu
- m_trayIconMenu = new QMenu(this);
+ // create a new icon menu
+ m_trayIconMenu = new QMenu(this);
- // 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);
+ // 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);
- // create new tray icon
- m_trayIcon = new QSystemTrayIcon(this);
+ // create new tray icon
+ m_trayIcon = new QSystemTrayIcon(this);
- // associate the menu with the tray icon
- m_trayIcon->setContextMenu(m_trayIconMenu);
+ // associate the menu with the tray icon
+ m_trayIcon->setContextMenu(m_trayIconMenu);
- // handle left click of icon
- connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
+ // handle left click of icon
+ connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason)));
}
void ChronoShareGui::setIcon()
{
- // set the icon image
- m_trayIcon->setIcon(QIcon(":/images/friends-group-icon.png"));
+ // set the icon image
+ m_trayIcon->setIcon(QIcon(":/images/friends-group-icon.png"));
}
void ChronoShareGui::openSharedFolder()
{
- // tell Finder to open the shared folder
- QStringList scriptArgs;
- scriptArgs << QLatin1String("-e")
- << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
- .arg(m_dirPath);
+ // Alex: isn't there an OS-independent way in QT for this?
- // execute the commands to make it happen
- QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
+ // tell Finder to open the shared folder
+ QStringList scriptArgs;
+ scriptArgs << QLatin1String("-e")
+ << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
+ .arg(m_dirPath);
- // clear command arguments
- scriptArgs.clear();
+ // execute the commands to make it happen
+ QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
- // tell Finder to appear
- scriptArgs << QLatin1String("-e")
- << QLatin1String("tell application \"Finder\" to activate");
+ // clear command arguments
+ scriptArgs.clear();
- // execute the commands to make it happen
- QProcess::execute("/usr/bin/osascript", scriptArgs);
+ // tell Finder to appear
+ scriptArgs << QLatin1String("-e")
+ << QLatin1String("tell application \"Finder\" to activate");
+
+ // execute the commands to make it happen
+ QProcess::execute("/usr/bin/osascript", scriptArgs);
}
void ChronoShareGui::openFileDialog()
{
- // prompt user for new directory
- QString tempPath = QFileDialog::getExistingDirectory(this, tr("Choose a new folder"),
- m_dirPath, QFileDialog::ShowDirsOnly |
- QFileDialog::DontResolveSymlinks);
- QFileInfo qFileInfo(tempPath);
+ // prompt user for new 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.");
+ 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.");
+ _LOG_DEBUG ("Selected path: " << m_dirPath.toStdString ());
- // save settings
- saveSettings();
+ 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();
}
-void ChronoShareGui::trayIconClicked(QSystemTrayIcon::ActivationReason reason)
+void ChronoShareGui::trayIconClicked (QSystemTrayIcon::ActivationReason reason)
{
- // if double clicked, open shared folder
- if(reason == QSystemTrayIcon::DoubleClick)
+ // if double clicked, open shared folder
+ if(reason == QSystemTrayIcon::DoubleClick)
{
- openSharedFolder();
+ openSharedFolder();
}
}
void ChronoShareGui::viewSettings()
{
- // simple for now
- openMessageBox("Chronoshare Settings", "CurrentFolder:\n" + m_dirPath);
+ // simple for now
+ openMessageBox("Chronoshare Settings", "CurrentFolder:\n" + m_dirPath);
}
bool ChronoShareGui::loadSettings()
{
- bool successful = false;
+ bool successful = false;
- // Load Settings
- QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
-
- qDebug() << settings.allKeys();
-
- if(settings.contains("dirPath"))
- {
- m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
- successful = true;
- }
- else
- {
- m_dirPath = QDir::homePath();
- successful = false;
- }
-
- qDebug() << "success: " << successful;
+ // Load Settings
+ // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
+ QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
- return successful;
+ // _LOG_DEBUG (lexical_cast<string> (settings.allKeys()));
+
+ if(settings.contains("dirPath"))
+ {
+ m_dirPath = settings.value("dirPath", QDir::homePath()).toString();
+ successful = true;
+ }
+ else
+ {
+ m_dirPath = QDir::homePath();
+ successful = false;
+ }
+
+ _LOG_DEBUG ("Found configured path: " << (successful? m_dirPath.toStdString () : std::string("no")));
+
+ return successful;
}
void ChronoShareGui::saveSettings()
{
- qDebug() << m_settingsFilePath;
- qDebug() << m_dirPath;
-
- // Save Settings
- QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
- settings.setValue("dirPath", m_dirPath);
+ // Save Settings
+ // QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
+ QSettings settings (QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
+ settings.setValue("dirPath", m_dirPath);
}
void ChronoShareGui::closeEvent(QCloseEvent* event)
{
- qDebug() << "Close Event.";
- event->ignore(); // don't let the event propagate to the base class
+ _LOG_DEBUG ("Close Event")
+ event->ignore(); // don't let the event propagate to the base class
}
#if WAF
#include "chronosharegui.moc"
#include "chronosharegui.cpp.moc"
-#endif
\ No newline at end of file
+#endif