Skip to content
Permalink
Browse files
working ui checkboxes
  • Loading branch information
feroze committed Apr 13, 2012
1 parent ecd7fd7 commit 9b0d330f25d02560ce7353ec18e2c3d487b5b329
@@ -45,6 +45,7 @@
#include "FirstRunWizard.h"

#include <QtGui>
#include <QPainter>

#ifdef Q_WS_MAC
#include <Carbon/Carbon.h>
@@ -131,6 +132,8 @@ MainWindow::MainWindow()

VidaliaSettings settings;

_streams = 0;

#if defined(Q_WS_MAC)
/* Display OSX dock icon if icon preference is not set to "Tray Only" */
if (settings.getIconPref() != VidaliaSettings::Tray) {
@@ -462,6 +465,8 @@ MainWindow::createConnections()
this, SLOT(bootstrapStatusChanged(BootstrapStatus)));
connect(_torControl, SIGNAL(dangerousPort(quint16, bool)),
this, SLOT(warnDangerousPort(quint16, bool)));
connect(_torControl, SIGNAL(streamStatusChanged(Stream)),
this, SLOT(addStreamToTrayIcon(Stream)));

connect(ui.tabWidget, SIGNAL(tabCloseRequested(int)),
this, SLOT(handleCloseTab(int)));
@@ -1684,6 +1689,7 @@ MainWindow::updateTorStatus(TorStatus status)
_trayIcon.setToolTip(statusText);
_statusTab.setTorStatus(statusText);
}
_trayIconFile = trayIconFile;
return prevStatus;
}

@@ -2286,3 +2292,41 @@ MainWindow::trayMessage(const QString &title, const QString &msg,
{
_trayIcon.showMessage(title, msg, icon, milli);
}

void
MainWindow::addStreamToTrayIcon(const Stream &stream)
{
VidaliaSettings settings;
if (!settings.showStreams())
return;
Stream::Status status = stream.status();
switch (status) {
case Stream::New:
_streams++;
break;
case Stream::Closed:
case Stream::Failed:
if (_streams<=1) {
_streams = 0;
setTrayIcon(_trayIconFile);
return;
}
else
_streams--;
}

QPixmap mask(_trayIconFile);
QPainter painter;
painter.begin(&mask);
QRect rect = mask.rect();

int bottom = rect.bottom();
rect.setTop(0.2 * bottom);
rect.setBottom(1.2 * bottom);

painter.drawText(rect,Qt::AlignCenter, QString::number(_streams));
painter.end();

_trayIcon.setIcon(mask);
_trayIcon.show();
}
@@ -61,6 +61,7 @@ public slots:
void trayMessage(const QString &title, const QString &msg,
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information,
int milli = 10000);
void addStreamToTrayIcon(const Stream &stream);

protected:
/** Called when the user changes the UI translation. */
@@ -278,6 +279,9 @@ private slots:
bool _useSavedPassword;
/** The Vidalia icon that sits in the tray. */
QSystemTrayIcon _trayIcon;
/** Stores path to tray icon. */
QString _trayIconFile;
int _streams;

#if defined(USE_AUTOUPDATE)
/** Timer used to remind us to check for software updates. */
@@ -220,6 +220,7 @@ AdvancedPage::save(QString &errmsg)
VidaliaSettings vsettings;
vsettings.setAllowPanic(ui.chkEnablePanic->isChecked());
vsettings.setPanicPath(ui.linePanicPath->text());
vsettings.setShowStreams(ui.chkShowStreams->isChecked());

#if 0
#if defined(Q_WS_WIN)
@@ -269,6 +270,7 @@ AdvancedPage::load()

ui.chkEnablePanic->setChecked(settings.allowPanic());
ui.linePanicPath->setText(settings.panicPath());
ui.chkShowStreams->setChecked(settings.showStreams());
}

/** Called when the user selects a different authentication method from the
@@ -486,6 +486,25 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="grpStreamStatus">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="title">
<string>Stream Indicator</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="chkShowStreams">
<property name="text">
<string>Enable stream status indicator</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@@ -41,6 +41,7 @@
#define SETTING_ALLOW_PANIC "AllowPanic"
#define SETTING_PANIC_PATH "PanicPath"
#define SETTING_FIRST_RUN "FirstRun"
#define SETTING_SHOW_STREAMS "ShowStreams"

#if defined(Q_OS_WIN32)
#define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@@ -90,6 +91,7 @@ VidaliaSettings::VidaliaSettings()
setDefault(SETTING_ALLOW_PANIC, false);
setDefault(SETTING_PANIC_PATH, "");
setDefault(SETTING_FIRST_RUN, true);
setDefault(SETTING_SHOW_STREAMS, false);
}

/** Gets the currently preferred language code for Vidalia. */
@@ -380,3 +382,15 @@ VidaliaSettings::setFirstRun(bool val)
{
setValue(SETTING_FIRST_RUN, val);
}

bool
VidaliaSettings::showStreams() const
{
return value(SETTING_SHOW_STREAMS).toBool();
}

void
VidaliaSettings::setShowStreams(bool val)
{
setValue(SETTING_SHOW_STREAMS, val);
}
@@ -151,6 +151,11 @@ class VidaliaSettings : public VSettings
bool firstRun() const;
/** Sets Vidalia's first run option */
void setFirstRun(bool val);

/** Returns true if stream status indicator is enabled */
bool showStreams() const;
/** Sets stream status indicator option */
void setShowStreams(bool val);
};

#endif

0 comments on commit 9b0d330

Please sign in to comment.