commit 8861dad970f60dc9c9cf888148cfd72ba5be4d15 Author: Jason Klein trac.torproject.org@my.jrklein.com Date: Sun Apr 17 17:13:25 2011 -0500
Implement Icon Preference (appearance setting) in OSX (see #2163)
Updated the Appearance settings page to include an Icon Preference group box with three new radio options: Show Tray Icon and Dock Icon Hide the Dock Icon Hide the Tray Icon
In order to hide the Dock Icon, I had to create a custom Info.plist file with LSUIElement set to "1" so OSX would launch Vidalia in the background (without Dock Icon). I then use TransformProcessType to force Vidalia to the foreground (show Dock Icon).
Hiding the Tray Icon was trival. I only call "_trayIcon.setIcon" if the user wants to see the System/Tray Icon.
By default, the user will continue to see Tray Icon and Dock Icon.
Conflicts:
src/vidalia/MainWindow.cpp src/vidalia/config/VidaliaSettings.cpp src/vidalia/config/VidaliaSettings.h --- pkg/osx/MacOSXBundleInfo.plist.in | 38 ++++++++++++++++++++++ src/vidalia/CMakeLists.txt | 3 ++ src/vidalia/MainWindow.cpp | 23 +++++++++++++- src/vidalia/config/AppearancePage.cpp | 28 ++++++++++++++++ src/vidalia/config/AppearancePage.ui | 55 ++++++++++++++++++++++++++++++++ src/vidalia/config/VidaliaSettings.cpp | 16 +++++++++ src/vidalia/config/VidaliaSettings.h | 7 ++++ 7 files changed, 169 insertions(+), 1 deletions(-)
diff --git a/pkg/osx/MacOSXBundleInfo.plist.in b/pkg/osx/MacOSXBundleInfo.plist.in new file mode 100644 index 0000000..3b5bfe0 --- /dev/null +++ b/pkg/osx/MacOSXBundleInfo.plist.in @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> + <key>CFBundleGetInfoString</key> + <string>${MACOSX_BUNDLE_INFO_STRING}</string> + <key>CFBundleIconFile</key> + <string>${MACOSX_BUNDLE_ICON_FILE}</string> + <key>CFBundleIdentifier</key> + <string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleLongVersionString</key> + <string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string> + <key>CFBundleName</key> + <string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> + <key>CSResourcesFileMapped</key> + <true/> + <key>LSRequiresCarbon</key> + <true/> + <key>NSHumanReadableCopyright</key> + <string>${MACOSX_BUNDLE_COPYRIGHT}</string> + <key>LSUIElement</key> + <string>1</string> +</dict> +</plist> diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt index 9fd58ca..efd9c7e 100644 --- a/src/vidalia/CMakeLists.txt +++ b/src/vidalia/CMakeLists.txt @@ -336,6 +336,9 @@ if (APPLE) set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/) add_executable(${vidalia_BIN} MACOSX_BUNDLE ${vidalia_SRCS})
+ ## Specify location of custom Info.plist file + set_target_properties(${vidalia_BIN} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ../pkg/osx/MacOSXBundleInfo.plist.in) + ## Get the location of the app bundle for the current configuration get_target_property(VIDALIA_EXECUTABLE ${vidalia_BIN} LOCATION) get_filename_component(MACOSX_BUNDLE_DIRECTORY ${VIDALIA_EXECUTABLE} PATH) diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp index 8dbf8ae..8b57e24 100644 --- a/src/vidalia/MainWindow.cpp +++ b/src/vidalia/MainWindow.cpp @@ -43,6 +43,10 @@
#include <QtGui>
+#ifdef Q_WS_MAC +#include <Carbon/Carbon.h> +#endif + #define IMG_BWGRAPH ":/images/16x16/utilities-system-monitor.png" #define IMG_CONTROL_PANEL ":/images/16x16/system-run.png" #define IMG_MESSAGELOG ":/images/16x16/format-justify-fill.png" @@ -115,6 +119,16 @@ MainWindow::MainWindow() _status = Unset; _isVidaliaRunningTor = false; updateTorStatus(Stopped); + +#if defined(Q_WS_MAC) + /* Display OSX dock icon if icon preference is not set to "Tray Only" */ + if (settings.getIconPref() != "Tray") { + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + } + /* Vidalia launched in background (LSUIElement=true). Bring to foreground. */ + VidaliaWindow::setVisible(true); +#endif }
/** Destructor */ @@ -1420,9 +1434,16 @@ void MainWindow::setTrayIcon(const QString &iconFile) { #if defined(Q_WS_MAC) + VidaliaSettings settings; QApplication::setWindowIcon(QPixmap(iconFile)); -#endif + + /* only display tray icon if icon preference is not set to "Dock Only" */ + if (settings.getIconPref() != "Dock") + _trayIcon.setIcon(QIcon(iconFile)); +#else + /* always display tray icon for other platforms */ _trayIcon.setIcon(QIcon(iconFile)); +#endif }
/** Converts a TorStatus enum value to a string for debug logging purposes. */ diff --git a/src/vidalia/config/AppearancePage.cpp b/src/vidalia/config/AppearancePage.cpp index 11939c3..647b67a 100644 --- a/src/vidalia/config/AppearancePage.cpp +++ b/src/vidalia/config/AppearancePage.cpp @@ -72,6 +72,21 @@ AppearancePage::save(QString &errmsg) /* Set the new style */ Vidalia::setStyle(ui.cmboStyle->currentText()); _settings->setInterfaceStyle(ui.cmboStyle->currentText()); + +#if defined(Q_WS_MAC) + /* Save new icon preference */ + if(ui.rdoIconPrefDock->isChecked()) { + _settings->setIconPref("Dock"); + } + else if(ui.rdoIconPrefTray->isChecked()) { + _settings->setIconPref("Tray"); + } + else { + /* default setting */ + _settings->setIconPref("Both"); + } +#endif + return true; }
@@ -84,5 +99,18 @@ AppearancePage::load()
index = ui.cmboStyle->findData(Vidalia::style().toLower()); ui.cmboStyle->setCurrentIndex(index); + +#if defined(Q_WS_MAC) + /* set current icon preference */ + ui.rdoIconPrefBoth->setChecked(_settings->getIconPref() == "Both"); + ui.rdoIconPrefTray->setChecked(_settings->getIconPref() == "Tray"); + ui.rdoIconPrefDock->setChecked(_settings->getIconPref() == "Dock"); +#else + /* hide preference on non-OSX platforms */ + ui.grpIconPref->setVisible(false); + ui.rdoIconPrefBoth->setVisible(false); + ui.rdoIconPrefTray->setVisible(false); + ui.rdoIconPrefDock->setVisible(false); +#endif }
diff --git a/src/vidalia/config/AppearancePage.ui b/src/vidalia/config/AppearancePage.ui index 8672af3..ef7ef5f 100644 --- a/src/vidalia/config/AppearancePage.ui +++ b/src/vidalia/config/AppearancePage.ui @@ -111,6 +111,61 @@ </widget> </item> <item> + <widget class="QGroupBox" name="grpIconPref"> + <property name="minimumSize"> + <size> + <width>0</width> + <height>100</height> + </size> + </property> + <property name="contextMenuPolicy"> + <enum>Qt::PreventContextMenu</enum> + </property> + <property name="title"> + <string>System Icon Preferences (changes will take effect when you restart Vidalia)</string> + </property> + <widget class="QRadioButton" name="rdoIconPrefBoth"> + <property name="geometry"> + <rect> + <x>20</x> + <y>30</y> + <width>441</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Show the Tray Icon and Dock Icon (default)</string> + </property> + </widget> + <widget class="QRadioButton" name="rdoIconPrefDock"> + <property name="geometry"> + <rect> + <x>20</x> + <y>70</y> + <width>441</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Hide the Tray Icon</string> + </property> + </widget> + <widget class="QRadioButton" name="rdoIconPrefTray"> + <property name="geometry"> + <rect> + <x>20</x> + <y>50</y> + <width>441</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Hide the Dock Icon</string> + </property> + </widget> + </widget> + </item> + <item> <spacer> <property name="orientation" > <enum>Qt::Vertical</enum> diff --git a/src/vidalia/config/VidaliaSettings.cpp b/src/vidalia/config/VidaliaSettings.cpp index aa4d18b..5cbf067 100644 --- a/src/vidalia/config/VidaliaSettings.cpp +++ b/src/vidalia/config/VidaliaSettings.cpp @@ -46,6 +46,7 @@ #define VIDALIA_REG_KEY "Vidalia" #endif
+#define SETTING_ICON_PREF "IconPref"
/** Default Constructor */ VidaliaSettings::VidaliaSettings() @@ -84,6 +85,7 @@ VidaliaSettings::VidaliaSettings() setDefault(SETTING_USE_LOCAL_GEOIP_DATABASE, false); setDefault(SETTING_LOCAL_GEOIP_DATABASE, ""); setDefault(SETTING_PLUGIN_PATH, vApp->dataDirectory()); + setDefault(SETTING_ICON_PREF, "Both"); }
/** Gets the currently preferred language code for Vidalia. */ @@ -334,3 +336,17 @@ VidaliaSettings::setPluginPath(const QString &path) { setValue(SETTING_PLUGIN_PATH, path); } + +/** Get the icon preference */ +QString +VidaliaSettings::getIconPref() const +{ + return value(SETTING_ICON_PREF).toString(); +} + +/** Set the icon preference */ +void +VidaliaSettings::setIconPref(const QString &iconPref) +{ + setValue(SETTING_ICON_PREF, iconPref); +} diff --git a/src/vidalia/config/VidaliaSettings.h b/src/vidalia/config/VidaliaSettings.h index 029657f..da8f0a4 100644 --- a/src/vidalia/config/VidaliaSettings.h +++ b/src/vidalia/config/VidaliaSettings.h @@ -130,6 +130,13 @@ public: QString pluginPath() const; /** Sets the path where the plugins live */ void setPluginPath(const QString &path); + + /** Get the icon preference */ + QString getIconPref() const; + + /** Set the icon preference */ + void setIconPref(const QString &iconPref); +>>>>>>> 4df4ee1... Implement Icon Preference (appearance setting) in OSX (see #2163) };
#endif
tor-commits@lists.torproject.org