Example #1
0
bool Autostart::Active()
{
#ifdef Q_OS_WIN
  QString applicationName = QCoreApplication::applicationName();
  QSettings tmpSettings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat );
  return !tmpSettings.value( applicationName ).toString().isEmpty();
#elif defined(Q_OS_MAC)

  LSSharedFileListRef loginItems = LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL );

  if( !loginItems ) {
    return false;
  }

  UInt32 seed = 0U;
  CFArrayRef currentLoginItems = LSSharedFileListCopySnapshot( loginItems, &seed );
  LSSharedFileListItemRef existingItem = FindLoginItemForCurrentBundle( currentLoginItems );

  bool isAutoRun = existingItem != NULL;

  CFRelease( currentLoginItems );
  CFRelease( loginItems );

  return isAutoRun;
#elif defined Q_WS_X11 || defined Q_OS_LINUX
    #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
        QString homeLocation = QStandardPaths::writableLocation( QStandardPaths::HomeLocation );
    #else
        QString homeLocation = QDesktopServices::storageLocation( QDesktopServices::HomeLocation );
    #endif
    QDir* autostartPath = new QDir(homeLocation + "/.config/autostart/");
    return autostartPath->exists("track-o-bot.desktop");
#endif
  return false;
}
Example #2
0
int SettingsDialog::getLangIndex()
{
    QSettings tmpSettings(QString("/etc/%1.ini").arg(qApp->applicationName()), QSettings::IniFormat);
    tmpSettings.sync();

    int langIndex = tmpSettings.value("general_settings/language_index", 0).toInt();

    if (langIndex < 0 || langIndex > getQmList().size()) {
        langIndex = 0;
    }

    return langIndex;
}
Example #3
0
void Autostart::SetActive( bool active )
{
#ifdef Q_OS_WIN
  QString applicationName = QCoreApplication::applicationName();
  QString applicationPath = QCoreApplication::applicationFilePath();

  QSettings tmpSettings( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat );
  if( active ) {
    tmpSettings.setValue( applicationName,
      QString( "\"%1\"" ).arg( QDir::toNativeSeparators( QFileInfo( applicationPath ).filePath() ) )
    );
  } else {
    tmpSettings.remove(applicationName);
  }

#elif defined(Q_OS_MAC)
  LSSharedFileListRef loginItems = LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL );

  if( !loginItems )
    return;

  UInt32 seed = 0U;
  CFArrayRef currentLoginItems = LSSharedFileListCopySnapshot( loginItems, &seed );
  LSSharedFileListItemRef existingItem = FindLoginItemForCurrentBundle( currentLoginItems );

  if( active && (existingItem == NULL) ) {
    CFURLRef mainBundleURL = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
    LSSharedFileListInsertItemURL( loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, mainBundleURL, NULL, NULL );
    CFRelease( mainBundleURL );
  }
  else if( !active && (existingItem != NULL) ) {
    LSSharedFileListItemRemove(loginItems, existingItem);
  }

  CFRelease( currentLoginItems );
  CFRelease( loginItems );
#elif defined Q_OS_LINUX
    QString homeLocation = QStandardPaths::writableLocation( QStandardPaths::HomeLocation );
    QDir* autostartPath = new QDir(homeLocation + "/.config/autostart/");
    if( !active ) {
        QFile* desktopFile = new QFile(autostartPath->filePath("track-o-bot.desktop"));
        desktopFile->remove();
    } else {
        QFile* srcFile = new QFile( ":/assets/track-o-bot.desktop" );
        LOG("source: %s", srcFile->fileName().toStdString().c_str());
        LOG("source exists: %s", QString::number(srcFile->exists()).toStdString().c_str());
        srcFile->copy(autostartPath->filePath("track-o-bot.desktop"));
    }
#endif
}