Added simple toaster for download complete.

Added new icon in MainWindow and systray icon for existing completed downloads.
You can enable/disable the toaster and the systray icon in NotifyPage.
Recompile of the GUI needed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3868 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-11-25 00:20:25 +00:00
parent e7813892bc
commit fc08d1171f
22 changed files with 656 additions and 70 deletions

View file

@ -0,0 +1,129 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (C) 2007 - 2010 Xesc & Technology
* Copyright (c) 2010 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*************************************************************************/
#include <QTimer>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QMessageBox>
#include <QFileInfo>
#include "DownloadToaster.h"
#include <retroshare/rsfiles.h>
DownloadToaster::DownloadToaster(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
setupUi(this);
/* set window flags */
QWidget::setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
/* init the timer */
displayTimer = new QTimer(this);
connect(displayTimer, SIGNAL(timeout()), this, SLOT(displayTimerOnTimer()));
/* connect buttons */
connect(spbClose, SIGNAL(clicked()), this, SLOT(closeClicked()));
connect(startButton, SIGNAL(clicked()), this, SLOT(play()));
/* init state */
displayState = dsInactive;
}
DownloadToaster::~DownloadToaster()
{
delete displayTimer;
}
void DownloadToaster::displayTimerOnTimer()
{
if (!isVisible()) return;
QDesktopWidget *desktop = QApplication::desktop();
QRect availableGeometry = desktop->availableGeometry(this);
// display popup animation
if (displayState == dsShowing)
if (pos().x() > availableGeometry.width() - size().width())// - 15)
move(pos().x() - 2, pos().y());
else
{
displayState = dsWaiting;
displayTimer->start(5000);
}
// hide popup animation
else if (displayState == dsHiding)
if (pos().x() < availableGeometry.width())
move(pos().x() + 2, pos().y());
else
{
displayState = dsWaiting;
displayTimer->stop();
hide();
}
else if (displayState == dsWaiting)
{
displayState = dsHiding;
displayTimer->start(2);
}
}
void DownloadToaster::displayPopup(const std::string &hash, const QString &name)
{
fileHash = hash;
labelTitle->setText(name);
QDesktopWidget *desktop = QApplication::desktop();
QRect availableGeometry = desktop->availableGeometry(this);
move(desktop->width(), availableGeometry.height() - size().height());
show();
displayState = dsShowing;
displayTimer->start(2);
}
void DownloadToaster::closeClicked()
{
displayState = dsHiding;
displayTimer->start(2);
}
void DownloadToaster::play()
{
/* look up path */
FileInfo fi;
if (!rsFiles->FileDetails(fileHash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, fi)) {
return;
}
std::string filename = fi.path + "/" + fi.fname;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(filename.c_str());
if (qinfo.exists()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()));
}else{
QMessageBox::information(this, "RetroShare", tr("File %1 does not exist at location.").arg(fi.path.c_str()));
}
}

View file

@ -0,0 +1,50 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (C) 2007 - 2010 Xesc & Technology
* Copyright (c) 2010 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*************************************************************************/
#ifndef DOWNLOADTOASTER_H
#define DOWNLOADTOASTER_H
#include "MessageToaster.h" // for DisplayState
#include "ui_DownloadToaster.h"
class DownloadToaster : public QWidget, public Ui::DownloadToaster
{
Q_OBJECT
public:
DownloadToaster(QWidget *parent = 0, Qt::WFlags f = 0);
~DownloadToaster();
void displayPopup(const std::string &hash, const QString &name);
private slots:
void displayTimerOnTimer();
void closeClicked();
void play();
private:
QTimer *displayTimer;
std::string fileHash;
DisplayState displayState;
};
#endif

View file

@ -0,0 +1,226 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DownloadToaster</class>
<widget class="QWidget" name="DownloadToaster">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>100</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string/>
</property>
<widget class="QLabel" name="labelTitle">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>241</width>
<height>61</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>117</red>
<green>116</green>
<blue>118</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>247</green>
<blue>221</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QToolButton" name="startButton">
<property name="geometry">
<rect>
<x>260</x>
<y>43</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Start file</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/player_play.png</normaloff>:/images/player_play.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="lblTitle">
<property name="geometry">
<rect>
<x>28</x>
<y>1</y>
<width>248</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>&lt;b&gt;Download completed&lt;/b&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>4</x>
<y>3</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/accepted16.png</pixmap>
</property>
</widget>
<widget class="QToolButton" name="spbClose">
<property name="geometry">
<rect>
<x>279</x>
<y>1</y>
<width>20</width>
<height>20</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Close</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/closenormal.png</normaloff>:/images/closenormal.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>100</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/finished_background.png</pixmap>
</property>
</widget>
<zorder>label_2</zorder>
<zorder>labelTitle</zorder>
<zorder>startButton</zorder>
<zorder>lblTitle</zorder>
<zorder>label</zorder>
<zorder>spbClose</zorder>
</widget>
<tabstops>
<tabstop>startButton</tabstop>
<tabstop>spbClose</tabstop>
</tabstops>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -93,8 +93,6 @@ void MessageToaster::displayPopup()
move(desktop->width(), availableGeometry.height() - size().height());
this->show();
alpha = 0;
displayState = dsShowing;
displayTimer->start(2);
}

View file

@ -51,8 +51,6 @@ Q_OBJECT
private:
QTimer *displayTimer;
QString videoFile;
DisplayState displayState;
double alpha;
};
#endif

View file

@ -41,7 +41,9 @@ QtToaster::QtToaster(QObject *master, QWidget * toaster, QFrame * toasterWindowF
_toaster->setAttribute ( Qt::WA_DeleteOnClose, true );
_master = master;
WidgetBackgroundImage::setBackgroundImage(toasterWindowFrame, ":images/toaster/toaster-backrs4.png", WidgetBackgroundImage::AdjustSize);
if (toasterWindowFrame) {
WidgetBackgroundImage::setBackgroundImage(toasterWindowFrame, ":images/toaster/toaster-backrs4.png", WidgetBackgroundImage::AdjustSize);
}
_toaster->resize(184, 128);
}