示例#1
0
//PUBLIC
TrayUI::TrayUI() : QSystemTrayIcon(){
  qDebug() << "Starting Up System Updater Tray...";
  //Set all the initial flags ( <0 means do initial checks if appropriate)
  PKGSTATUS=-1;
  SYSSTATUS=-1;
  WARDENSTATUS=-1;
  noInternet = false; //assume internet is available until we get a failure
  wasworking = false;
  //Load the tray settings file
  settings = new QSettings("PCBSD");
    settings->sync(); //make sure to load it right away
  //Setup the checktimer
  chktime = new QTimer(this);
	chktime->setInterval(1000 * 60 * 60 * 24); //every 24 hours
	connect(chktime, SIGNAL(timeout()), this, SLOT(checkForUpdates()) );
  //Generate the Menu
  menu = new QMenu(0);
  this->setContextMenu(menu);
  connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(slotItemClicked(QAction*)) );
  //Now fill the menu with items
    // - System Update Manager
  QAction* act = new QAction( QIcon(":/images/sysupdater.png"), tr("Start the Update Manager"), this);
	act->setWhatsThis("sys"); //system updater code
	menu->addAction(act);
    // - Separator
  menu->addSeparator();
    // - AppCafe
  act = new QAction( QIcon(":/images/appcafe.png"), tr("Start the AppCafe"), this);
	act->setWhatsThis("pkg"); // PKG code
	menu->addAction(act);
    // - Warden
  act = new QAction( QIcon(":/images/warden.png"), tr("Start the Warden"), this);
	act->setWhatsThis("warden"); //warden code
	menu->addAction(act);
    // - Separator
  menu->addSeparator();
    // - Check for Updates
  act = new QAction( QIcon(":/images/view-refresh.png"), tr("Check For Updates"), this);
	act->setWhatsThis("update"); //update check code
	menu->addAction(act);
    // - Separator
  menu->addSeparator();
    // - Run At Startup Checkbox
  runAtStartup = new QCheckBox(tr("Run At Startup"), 0);
    runAtStartup->setChecked( settings->value("/PC-BSD/SystemUpdater/runAtStartup",true).toBool() );
    connect(runAtStartup, SIGNAL(clicked()), this, SLOT(slotRunAtStartupClicked()) );
  rasAct = new QWidgetAction(this);
    rasAct->setDefaultWidget(runAtStartup);
    menu->addAction(rasAct);
    // - Display Notifications Checkbox
  showNotifications = new QCheckBox(tr("Display Notifications"), 0);
    showNotifications->setChecked( settings->value("/PC-BSD/SystemUpdater/displayPopup",true).toBool() );
    connect(showNotifications, SIGNAL(clicked()), this, SLOT(slotShowMessagesClicked()) );
  snAct = new QWidgetAction(this);
    snAct->setDefaultWidget(showNotifications);
    menu->addAction(snAct);   

  makeScheduleMenu();
  menu->addAction(tr("Automatic updates check"))->setMenu(schedule_menu);

    // - Separator
  menu->addSeparator();
    // - Warden
  act = new QAction( tr("Quit"), this);
	act->setWhatsThis("quit"); //system updater code
	menu->addAction(act);

  //Now Update the tray visuals
  updateTrayIcon();
  updateToolTip();
  //Start up the system flag watcher and connect the signals/slots
  watcher = new SystemFlagWatcher(this);
	connect(watcher,SIGNAL(FlagChanged(SystemFlags::SYSFLAG, SystemFlags::SYSMESSAGE)),this,SLOT(watcherMessage(SystemFlags::SYSFLAG, SystemFlags::SYSMESSAGE)) );
  //watcher->checkForRecent(10); //Check for flags in the last 10 minutes
  
  //Now connect the tray clicked signal
  connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)) );
  connect(this, SIGNAL(messageClicked()), this, SLOT(launchApp()) );
  
  //Startup the initial checks in 1 minute
  QTimer::singleShot(60000, this, SLOT(startupChecks()));

  //Periodically check timer start
  checkTimer=new QTimer(this);
  checkTimer->setInterval(60000); // 1min
  connect(checkTimer, SIGNAL(timeout()), this, SLOT(slotCheckTimer()));
  checkTimer->start();

}
示例#2
0
文件: LPTray.cpp 项目: yater/pcbsd
//PUBLIC
LPTray::LPTray() : QSystemTrayIcon() {
    qDebug() << "Starting up Life-preserver Tray...";
    //Start up the log file watcher and connect the signals/slots
    watcher = new LPWatcher();
    connect(watcher,SIGNAL(MessageAvailable(QString)),this,SLOT(watcherMessage(QString)) );
    connect(watcher,SIGNAL(StatusUpdated()),this,SLOT(watcherMessage()) );
    //Load the tray settings file
    settings = new QSettings(QSettings::UserScope,"PCBSD", "life-preserver-tray");
    //Create the notification option widgets
    nShowAll = new QRadioButton(tr("Show all"));
    naAll = new QWidgetAction(this);
    naAll->setDefaultWidget(nShowAll);
    nShowError = new QRadioButton(tr("Warnings Only"));
    naErr = new QWidgetAction(this);
    naErr->setDefaultWidget(nShowError);
    nShowNone = new QRadioButton(tr("None"));
    naNone = new QWidgetAction(this);
    naNone->setDefaultWidget(nShowNone);
    //Create notification menu
    notificationMenu = new QMenu(tr("Popup Settings"));
    notificationMenu->setIcon( QIcon(":/images/configure.png") );
    notificationMenu->addAction(naAll);
    notificationMenu->addAction(naErr);
    notificationMenu->addAction(naNone);
    //Activate the proper notification setting widget
    QString popset = settings->value("popup-policy", "").toString();
    qDebug() << "Current Popup Policy:" << popset;
    if(popset=="all") {
        nShowAll->setChecked(true);
        popupPolicy = 2;
    }
    else if(popset=="errors") {
        nShowError->setChecked(true);
        popupPolicy = 1;
    }
    else if(popset=="none") {
        nShowNone->setChecked(true);
        popupPolicy = 0;
    }
    else {
        nShowError->setChecked(true);
        settings->setValue("popup-policy","errors"); //save the proper setting
        popupPolicy = 1;
    }
    //Now connect the popup settings signals/slots
    connect(nShowAll, SIGNAL(clicked()), this, SLOT(changePopupPolicy()) );
    connect(nShowError, SIGNAL(clicked()), this, SLOT(changePopupPolicy()) );
    connect(nShowNone, SIGNAL(clicked()), this, SLOT(changePopupPolicy()) );
    //Setup the context menu
    menu = new QMenu;
    menu->addAction(QIcon(":/images/tray-icon-idle.png"),tr("Open Life Preserver"),this,SLOT(startGUI()) );
    menu->addSeparator();
    menu->addAction(QIcon(":/images/backup-failed.png"),tr("View Messages"),this,SLOT(startMessageDialog()) );
    menu->addMenu(notificationMenu);
    menu->addAction(QIcon(":/images/refresh.png"),tr("Refresh Tray"),this,SLOT(refreshStatus()) );
    menu->addSeparator();
    menu->addAction(QIcon(":/images/application-exit.png"),tr("Close Tray"),this,SLOT(slotClose()) );
    this->setContextMenu(menu);
    //Setup initial icon for the tray
    this->setIcon( QIcon(":/images/tray-icon-idle.png") );
    //Create the messages GUI
    msgdlg = new LPMessages();
    //connect other signals/slots
    connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)) );
    //Start up the watcher
    watcher->start();
    updateTrayIcon();
    updateToolTip();
}