예제 #1
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
	userSettings = new QSettings("traygists_settings");
	lastUpdate = userSettings->value("LastUpdate", QDateTime::currentDateTimeUtc()).toDateTime();
	qDebug() << "Last updated: " << timeAgo(lastUpdate);

	trayIcon = new QSystemTrayIcon(QIcon(":/gists_black.png"), this);
	connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
	connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
	trayIcon->show();

	QAction *refreshAction = new QAction("Refresh", trayIcon);
	connect(refreshAction, SIGNAL(triggered()), this, SLOT(refreshGists()));


	QAction *aboutAction = new QAction("About", trayIcon);
	connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));

	QAction *quitAction = new QAction(tr("Exit"), trayIcon );
	quitAction->setShortcut(QKeySequence("CTRL+SHIFT+X"));
	connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));

	gistsMenu = new QMenu("gists");
	connect(gistsMenu, SIGNAL(triggered(QAction*)), this, SLOT(gistSelected(QAction*)));

	mainMenu = new QMenu;
	mainMenu->addAction(refreshAction);
	mainMenu->addMenu(gistsMenu);
	mainMenu->addSeparator();
	mainMenu->addAction(aboutAction);
	mainMenu->addAction(quitAction);
	trayIcon->setContextMenu(mainMenu);

	networkManager = new QNetworkAccessManager(this);
	connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(gistsFetched(QNetworkReply*)));

	// Start update routine
	updateTimer = new QTimer(this);
	connect(updateTimer, SIGNAL(timeout()), this, SLOT(refreshGists()));
	updateTimer->start();
}
예제 #2
0
파일: logs.cpp 프로젝트: mauroc/squiddio_pi
void logsWindow::OnPaint(wxPaintEvent& event) {
    wxPaintDC dc(this);
    wxColour cs;
    GetGlobalColor(_T("GREEN2"), &cs);
    wxColour cr;
    GetGlobalColor(_T("BLUE2"), &cr);
    wxColour ca;
    GetGlobalColor(_T("URED"), &ca);
    wxColour ci;
    GetGlobalColor(_T("DASHL"), &ci);
    wxColour cb;
    GetGlobalColor(_T("DASHB"), &cb);
    dc.SetBackground(cb);
    dc.SetTextBackground(cb);
    wxString lastRcvd, lastSent=wxEmptyString;

    wxFont *g_pFontSmall;
    g_pFontSmall = new wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
    dc.SetFont(*g_pFontSmall);

    if (m_LastLogSent.IsValid() && m_LastLogSent.GetYear() > 1970 ) // can't figure out how to assess if it is NULL
        lastSent = m_LastLogSent.Format(_T(" %a-%d-%b-%Y %H:%M:%S  "), wxDateTime::Local);

    if (m_LastLogsRcvd.IsValid() && m_LastLogsRcvd.GetYear() > 1970 )
        lastRcvd = m_LastLogsRcvd.Format(_T(" %a-%d-%b-%Y %H:%M:%S  "),wxDateTime::Local);

    dc.Clear();
    wxString data;
    wxString lastSentAv = (lastSent.Length() > 0 ? lastSent : _T("(awaiting NMEA events)"));

    if (p_plugin->g_PostPeriod > 0 && p_plugin->last_online) {
        dc.SetTextForeground(cs);
    } else {
        dc.SetTextForeground(ci);
    }

    // own log postings
    dc.DrawText(_("Log sent:"), 5, 5);
    dc.DrawText(timeAgo(m_LastLogSent),100,5);
    dc.DrawText(_T("(")+lastSent+_T(")"),250,5);

    // friends logs
    if (g_RetrieveSecs > 0 && p_plugin->last_online) {
        dc.SetTextForeground(cr);
    } else {
        dc.SetTextForeground(ci);
    }

    dc.DrawText(_T("|"),450,5);

    wxString demo_msg = _T("");
    if (p_plugin->g_ApiKey == _T("squiddio_demo_api"))
        demo_msg = _T(" (demo)");
    dc.DrawText(_("Logs received")+demo_msg+_T(":"), 480, 5);
    dc.DrawText(timeAgo(m_LastLogsRcvd),610,5);
    dc.DrawText(_T("(")+lastRcvd+_T(")"),750,5);

    dc.SetTextForeground(ca);
    dc.DrawText(m_ErrorCondition ,950, 5);

    dc.SetTextForeground(cr);
    dc.DrawText(m_Notice ,950, 5);

    m_pRefreshTimer->Stop();
    m_pRefreshTimer->Start(5000);
}