Exemplo n.º 1
0
void SystemFlagWatcher::watcherNotification(){
  //qDebug() << "Watcher found change";
  QDir dir(FLAGDIR);
  if(!dir.exists()){ return; } //flag directory does not exist yet - do nothing
  QDateTime oldCDT = CDT.addSecs(-1); //Always backup one second to make sure we get concurrently set flags
  CDT = QDateTime::currentDateTime(); //Update the last time flags were checked
  QFileInfoList flags = dir.entryInfoList( QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
  for(int i=0; i<flags.length(); i++){
     if(oldCDT < flags[i].lastModified()){
       QString contents = quickRead(flags[i].absoluteFilePath());
	SystemFlags::SYSMESSAGE msg;
	if(contents==MWORKING){ msg = SystemFlags::Working; }
	else if(contents==MERROR){ msg = SystemFlags::Error; }
	else if(contents==MSUCCESS){ msg = SystemFlags::Success; }
	else if(contents==MUPDATE){ msg = SystemFlags::UpdateAvailable; }
	else if(contents==MUPDATING){ msg = SystemFlags::Updating; }
	else{ continue; } //invalid message - skip this flag
       //New flag - check which one and emit the proper signal
       if(flags[i].fileName().startsWith(NETWORKRESTARTED) ){
         emit FlagChanged(SystemFlags::NetRestart, msg);
       }else if(flags[i].fileName().startsWith(PKGUPDATEAVAILABLE) ){
	 emit FlagChanged(SystemFlags::PkgUpdate, msg);
       }else if(flags[i].fileName().startsWith(SYSUPDATEAVAILABLE) ){
	 emit FlagChanged(SystemFlags::SysUpdate, msg);
       }else if(flags[i].fileName().startsWith(WARDENUPDATEAVAILABLE) ){
	 emit FlagChanged(SystemFlags::WardenUpdate, msg);
       }
     }
  }
  if(chktime->isActive()){ chktime->stop(); }
  chktime->start(); //restart the default timer
}
Exemplo n.º 2
0
void SystemFlagWatcher::watcherNotification() {
    //Does not specify the contents of a flag just yet - KenMoore 3/12/14
    QDir dir(FLAGDIR);
    if(!dir.exists()) {
        return;    //flag directory does not exist yet - do nothing
    }
    QFileInfoList flags = dir.entryInfoList( QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
    for(int i=0; i<flags.length(); i++) {
        if(CDT < flags[i].lastModified()) {
            QString contents = quickRead(flags[i].absoluteFilePath()); //add this later
            //New flag - check which one and emit the proper signal
            if(flags[i].fileName().startsWith(NETWORKRESTARTED) ) {
                emit FlagChanged(SystemFlags::NetRestart, contents);
            } else if(flags[i].fileName().startsWith(PKGUPDATEAVAILABLE) ) {
                emit FlagChanged(SystemFlags::PkgUpdate, contents);
            } else if(flags[i].fileName().startsWith(SYSUPDATEAVAILABLE) ) {
                emit FlagChanged(SystemFlags::SysUpdate, contents);
            } else if(flags[i].fileName().startsWith(PBIUPDATEAVAILABLE) ) {
                emit FlagChanged(SystemFlags::PbiUpdate, contents);
            }
        }
    }
    CDT = QDateTime::currentDateTime(); //Now update the last time flags were checked
}
Exemplo n.º 3
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();

}