当前位置: 首页>>代码示例>>C++>>正文


C++ LSSharedFileListItemRemove函数代码示例

本文整理汇总了C++中LSSharedFileListItemRemove函数的典型用法代码示例。如果您正苦于以下问题:C++ LSSharedFileListItemRemove函数的具体用法?C++ LSSharedFileListItemRemove怎么用?C++ LSSharedFileListItemRemove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LSSharedFileListItemRemove函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tmpSettings

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
}
开发者ID:CodeSheng,项目名称:track-o-bot,代码行数:50,代码来源:Autostart.cpp

示例2: SetStartOnSystemStartup

bool SetStartOnSystemStartup(bool fAutoStart)
{
    CFURLRef patacoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
    LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, patacoinAppUrl);

    if(fAutoStart && !foundItem) {
        // add patacoin app to startup item list
        LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, patacoinAppUrl, NULL, NULL);
    }
    else if(!fAutoStart && foundItem) {
        // remove item
        LSSharedFileListItemRemove(loginItems, foundItem);
    }
    return true;
}
开发者ID:Patacoin,项目名称:patacoin,代码行数:16,代码来源:guiutil.cpp

示例3: defined

void Utility::setLaunchOnStartup(const QString &appName, const QString& guiName, bool enable)
{
#if defined(Q_OS_WIN)
    Q_UNUSED(guiName)
    QString runPath = QLatin1String(runPathC);
    QSettings settings(runPath, QSettings::NativeFormat);
    if (enable) {
        settings.setValue(appName, QCoreApplication::applicationFilePath().replace('/','\\'));
    } else {
        settings.remove(appName);
    }
#elif defined(Q_OS_MAC)
    Q_UNUSED(guiName)
    QString filePath = QDir(QCoreApplication::applicationDirPath()+QLatin1String("/../..")).absolutePath();
    CFStringRef folderCFStr = CFStringCreateWithCString(0, filePath.toUtf8().data(), kCFStringEncodingUTF8);
    CFURLRef urlRef = CFURLCreateWithFileSystemPath (0, folderCFStr, kCFURLPOSIXPathStyle, true);
    LSSharedFileListRef loginItems = LSSharedFileListCreate(0, kLSSharedFileListSessionLoginItems, 0);

    if (loginItems && enable) {
        //Insert an item to the list.
        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,
                                                                     kLSSharedFileListItemLast, 0, 0,
                                                                     urlRef, 0, 0);
        if (item)
            CFRelease(item);
        CFRelease(loginItems);
    } else if (loginItems && !enable){
        // We need to iterate over the items and check which one is "ours".
        UInt32 seedValue;
        CFArrayRef itemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
        CFStringRef appUrlRefString = CFURLGetString(urlRef);
        for (int i = 0; i < CFArrayGetCount(itemsArray); i++) {
            LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(itemsArray, i);
            CFURLRef itemUrlRef = NULL;

            if (LSSharedFileListItemResolve(item, 0, &itemUrlRef, NULL) == noErr) {
                CFStringRef itemUrlString = CFURLGetString(itemUrlRef);
                if (CFStringCompare(itemUrlString,appUrlRefString,0) == kCFCompareEqualTo) {
                    LSSharedFileListItemRemove(loginItems,item); // remove it!
                }
                CFRelease(itemUrlRef);
            }
        }
        CFRelease(itemsArray);
        CFRelease(loginItems);
    };

    CFRelease(folderCFStr);
    CFRelease(urlRef);
#elif defined(Q_OS_UNIX)
    QString userAutoStartPath = QDir::homePath()+QLatin1String("/.config/autostart/");
    QString desktopFileLocation = userAutoStartPath+appName+QLatin1String(".desktop");
    if (enable) {
        if (!QDir().exists(userAutoStartPath) && !QDir().mkdir(userAutoStartPath)) {
            qDebug() << "Could not create autostart directory";
            return;
        }
        QFile iniFile(desktopFileLocation);
        if (!iniFile.open(QIODevice::WriteOnly)) {
            qDebug() << "Could not write auto start entry" << desktopFileLocation;
            return;
        }
        QTextStream ts(&iniFile);
        ts.setCodec("UTF-8");
        ts << QLatin1String("[Desktop Entry]") << endl
           << QLatin1String("Name=") << guiName << endl
           << QLatin1String("GenericName=") << QLatin1String("File Synchronizer") << endl
           << QLatin1String("Exec=") << QCoreApplication::applicationFilePath() << endl
           << QLatin1String("Terminal=") << "false" << endl
           << QLatin1String("Icon=") << appName << endl
           << QLatin1String("Categories=") << QLatin1String("Network") << endl
           << QLatin1String("Type=") << QLatin1String("Application") << endl
           << QLatin1String("StartupNotify=") << "false" << endl
           << QLatin1String("X-GNOME-Autostart-enabled=") << "true" << endl
            ;
    } else {
        if (!QFile::remove(desktopFileLocation)) {
            qDebug() << "Could not remove autostart desktop file";
        }
    }

#endif
}
开发者ID:Greyhatno,项目名称:mirall,代码行数:83,代码来源:utility.cpp

示例4: defined

void AsemanAutoStartManager::save()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_OPENBSD)
    const QString &pathDir = QDir::homePath() + "/.config/autostart";
    const QString &path = pathDir + "/" + p->source + ".desktop";

    QDir().mkpath(pathDir);

    QString data = QString("[Desktop Entry]") +
            "\nHidden=" + (p->active?"false":"true") +
            "\nX-GNOME-Autostart-enabled=" + (p->active?"true":"false") +
            "\nName=" + p->name +
            "\nName[en_US]=" + p->name +
            "\nComment=" + p->comment +
            "\nComment[en_US]=" + p->comment +
            "\nType=" + p->type +
            "\nExec=" + p->command +
            "\nNoDisplay=false\n";

    QFile file(path);
    if(!file.open(QFile::WriteOnly))
        return;

    file.write(data.toUtf8());
    file.close();
#elif defined(Q_OS_WIN)
    QSettings autoStartSettings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);

    if(p->active)
    {
        autoStartSettings.setValue(p->source, QDir::toNativeSeparators(QDir::cleanPath(p->command)));
    }
    else
    {
        autoStartSettings.remove(p->source);
    }
#elif defined(Q_OS_MAC) && defined(OSX_CORE_SERVICES_AVAILABLE)
    CFURLRef url = prepareURL(p->command);
    if (!url)
    {
        qWarning("unable to create CFURLRef");
        return;
    }

    LSSharedFileListRef login_items = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
    if (!login_items)
    {
        qWarning("unable to get login items");
        return;
    }

    CFArrayRef login_items_array = LSSharedFileListCopySnapshot(login_items, NULL);
    if (!login_items_array)
    {
        qWarning("unable to get login items array");
        CFRelease(login_items);
        return;
    }
    CFIndex count = CFArrayGetCount(login_items_array);
    CFStringRef url_string = CFURLGetString(url);
    CFURLRef item_url = NULL;
    for (CFIndex i = 0; i < count; i += 1)
    {
        LSSharedFileListItemRef item = (LSSharedFileListItemRef) CFArrayGetValueAtIndex(login_items_array, i);
        if (LSSharedFileListItemResolve(item, 0, &item_url, NULL) != 0)
        {
            qWarning("unable to resolve login item");
            CFRelease(login_items_array);
            CFRelease(login_items);
            return;
        }
        CFStringRef item_url_string = CFURLGetString(item_url);

        CFComparisonResult result = CFStringCompare(url_string, item_url_string, 0);
        CFRelease(item_url);
        if (result == kCFCompareEqualTo)
        {
            if (!p->active)
            {
                LSSharedFileListItemRemove(login_items, item);
                CFRelease(login_items_array);
                CFRelease(login_items);
                return;
            }

            qWarning("found in login items already");
            CFRelease(login_items_array);
            CFRelease(login_items);
            return;
        }
    }

    if (p->active)
    {
        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(
            login_items, kLSSharedFileListItemLast, p->name.toCFString(), NULL, url, NULL, NULL);
        if (!item)
        {
            qWarning("Unable to add to login items");
            CFRelease(login_items_array);
//.........这里部分代码省略.........
开发者ID:Aseman-Land,项目名称:aseman-qt-tools,代码行数:101,代码来源:asemanautostartmanager.cpp


注:本文中的LSSharedFileListItemRemove函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。