2008-05-03 09:37:10 -05:00
|
|
|
#include "drone.h"
|
|
|
|
|
2009-11-29 10:32:31 -06:00
|
|
|
#include "rpcserver.h"
|
|
|
|
#include "myservice.h"
|
|
|
|
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2009-11-03 08:02:09 -06:00
|
|
|
extern int myport;
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-11-29 10:32:31 -06:00
|
|
|
Drone::Drone(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-11-29 10:32:31 -06:00
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
rpcServer = new RpcServer();
|
|
|
|
service = new MyService();
|
|
|
|
}
|
2009-11-03 08:02:09 -06:00
|
|
|
|
2009-11-29 10:32:31 -06:00
|
|
|
Drone::~Drone()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
trayIcon_->hide();
|
|
|
|
delete rpcServer;
|
|
|
|
delete service;
|
2009-11-29 10:32:31 -06:00
|
|
|
}
|
2008-05-03 09:37:10 -05:00
|
|
|
|
2009-11-29 10:32:31 -06:00
|
|
|
bool Drone::init()
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
Q_ASSERT(rpcServer);
|
2009-11-29 10:32:31 -06:00
|
|
|
|
|
|
|
if (!rpcServer->registerService(service, myport ? myport : 7878))
|
2009-12-28 02:31:28 -06:00
|
|
|
{
|
|
|
|
QMessageBox::critical(0, qApp->applicationName(),
|
|
|
|
rpcServer->errorString());
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
trayIconMenu_ = new QMenu(this);
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
trayIconMenu_->addAction(actionShow);
|
|
|
|
trayIconMenu_->addAction(actionExit);
|
|
|
|
trayIconMenu_->setDefaultAction(actionShow);
|
|
|
|
trayIcon_ = new QSystemTrayIcon();
|
|
|
|
trayIcon_->setIcon(QIcon(":/icons/portgroup.png"));
|
|
|
|
trayIcon_->setToolTip(qApp->applicationName());
|
|
|
|
trayIcon_->setContextMenu(trayIconMenu_);
|
|
|
|
trayIcon_->show();
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
|
|
this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
|
|
|
|
connect(this, SIGNAL(hideMe(bool)), this, SLOT(setHidden(bool)),
|
|
|
|
Qt::QueuedConnection);
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
return true;
|
2009-11-29 10:32:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void Drone::changeEvent(QEvent *event)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (event->type() == QEvent::WindowStateChange && isMinimized())
|
|
|
|
{
|
|
|
|
emit hideMe(true);
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
2009-11-29 10:32:31 -06:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
QWidget::changeEvent(event);
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|
|
|
|
|
2009-11-29 10:32:31 -06:00
|
|
|
void Drone::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
2008-05-03 09:37:10 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (reason == QSystemTrayIcon::DoubleClick)
|
|
|
|
{
|
|
|
|
showNormal();
|
|
|
|
activateWindow();
|
|
|
|
}
|
2008-05-03 09:37:10 -05:00
|
|
|
}
|