Jared Lindblom | 06405c4 | 2013-01-17 20:48:39 -0800 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012-2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Jared Lindblom <lindblom@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "chronosharegui.h" |
| 22 | #include "ui_chronosharegui.h" |
| 23 | |
| 24 | ChronoShareGui::ChronoShareGui(QString dirPath, QWidget *parent) : |
| 25 | QWidget(parent), |
| 26 | m_dirPath(dirPath) |
| 27 | { |
| 28 | createActions(); |
| 29 | createTrayIcon(); |
| 30 | setIcon(); |
| 31 | |
| 32 | m_trayIcon->show(); |
| 33 | } |
| 34 | |
| 35 | ChronoShareGui::~ChronoShareGui() |
| 36 | { |
| 37 | delete m_trayIcon; |
| 38 | delete m_trayIconMenu; |
| 39 | delete m_openFolder; |
| 40 | delete m_quitProgram; |
| 41 | } |
| 42 | |
| 43 | void ChronoShareGui::createActions() |
| 44 | { |
| 45 | m_openFolder = new QAction(tr("&Open"), this); |
| 46 | connect(m_openFolder, SIGNAL(triggered()), this, SLOT(openSharedFolder())); |
| 47 | |
| 48 | m_quitProgram = new QAction(tr("&Quit"), this); |
| 49 | connect(m_quitProgram, SIGNAL(triggered()), qApp, SLOT(quit())); |
| 50 | } |
| 51 | |
| 52 | void ChronoShareGui::createTrayIcon() |
| 53 | { |
| 54 | m_trayIconMenu = new QMenu(this); |
| 55 | |
| 56 | m_trayIconMenu->addAction(m_openFolder); |
| 57 | m_trayIconMenu->addSeparator(); |
| 58 | m_trayIconMenu->addAction(m_quitProgram); |
| 59 | |
| 60 | m_trayIcon = new QSystemTrayIcon(this); |
| 61 | m_trayIcon->setContextMenu(m_trayIconMenu); |
| 62 | } |
| 63 | |
| 64 | void ChronoShareGui::setIcon() |
| 65 | { |
| 66 | m_trayIcon->setIcon(QIcon(":/images/friends-group-icon.png")); |
| 67 | } |
| 68 | |
| 69 | void ChronoShareGui::openSharedFolder() |
| 70 | { |
| 71 | QStringList scriptArgs; |
| 72 | scriptArgs << QLatin1String("-e") |
| 73 | << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"") |
| 74 | .arg(m_dirPath); |
| 75 | QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs); |
| 76 | scriptArgs.clear(); |
| 77 | scriptArgs << QLatin1String("-e") |
| 78 | << QLatin1String("tell application \"Finder\" to activate"); |
| 79 | QProcess::execute("/usr/bin/osascript", scriptArgs); |
| 80 | } |