Completely reworked the toasters. Now there is only one place that moves the toaster and the toasters are stacked.

Removed the chat and call toaster.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3900 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-12-08 00:14:12 +00:00
parent 9bb5f304b7
commit 2a69abe570
21 changed files with 357 additions and 2329 deletions

View file

@ -20,110 +20,47 @@
*
*************************************************************************/
#include <QTimer>
#include <QDesktopWidget>
#include <QDesktopServices>
#include <QMessageBox>
#include <QFileInfo>
#include <QUrl>
#include "DownloadToaster.h"
#include <retroshare/rsfiles.h>
DownloadToaster::DownloadToaster(QWidget * parent, Qt::WFlags flags)
: QWidget(parent, flags)
DownloadToaster::DownloadToaster(const std::string &hash, const QString &name) : QWidget(NULL)
{
setupUi(this);
ui.setupUi(this);
/* set window flags */
QWidget::setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
fileHash = hash;
/* init the timer */
displayTimer = new QTimer(this);
connect(displayTimer, SIGNAL(timeout()), this, SLOT(displayTimerOnTimer()));
/* connect buttons */
connect(ui.spbClose, SIGNAL(clicked()), this, SLOT(hide()));
connect(ui.startButton, SIGNAL(clicked()), this, SLOT(play()));
/* 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);
/* set informations */
ui.labelTitle->setText(name);
}
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;
}
/* 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;
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()));
}
/* 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()));
}
hide();
}