• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ LSSharedFileListInsertItemURL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了LSSharedFileListInsertItemURL函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: SHGetSpecialFolderPath

void Utility::setupFavLink(const QString &folder)
{
#ifdef Q_OS_WIN
    // Windows Explorer: Place under "Favorites" (Links)
    wchar_t path[MAX_PATH];
    SHGetSpecialFolderPath(0, path, CSIDL_PROFILE, FALSE);
    QString profile =  QDir::fromNativeSeparators(QString::fromWCharArray(path));
    QDir folderDir(QDir::fromNativeSeparators(folder));
    QString linkName = profile+QLatin1String("/Links/") + folderDir.dirName() + QLatin1String(".lnk");
    if (!QFile::link(folder, linkName))
        qDebug() << Q_FUNC_INFO << "linking" << folder << "to" << linkName << "failed!";
#elif defined (Q_OS_MAC)
    // Finder: Place under "Places"/"Favorites" on the left sidebar
    CFStringRef folderCFStr = CFStringCreateWithCString(0, folder.toUtf8().data(), kCFStringEncodingUTF8);
    CFURLRef urlRef = CFURLCreateWithFileSystemPath (0, folderCFStr, kCFURLPOSIXPathStyle, true);

    LSSharedFileListRef placesItems = LSSharedFileListCreate(0, kLSSharedFileListFavoriteItems, 0);
    if (placesItems) {
        //Insert an item to the list.
        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(placesItems,
                                                                     kLSSharedFileListItemLast, 0, 0,
                                                                     urlRef, 0, 0);
        if (item)
            CFRelease(item);
    }
    CFRelease(placesItems);
    CFRelease(folderCFStr);
    CFRelease(urlRef);
#elif defined (Q_OS_UNIX)
    // Nautilus: add to ~/.gtk-bookmarks
    QFile gtkBookmarks(QDir::homePath()+QLatin1String("/.gtk-bookmarks"));
    QByteArray folderUrl = "file://" + folder.toUtf8();
    if (gtkBookmarks.open(QFile::ReadWrite)) {
        QByteArray places = gtkBookmarks.readAll();
        if (!places.contains(folderUrl)) {
            places += folderUrl;
            gtkBookmarks.reset();
            gtkBookmarks.write(places + '\n');
        }


    }

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


示例4: InsertLoginItem

void
InsertLoginItem(const char *cpath)
{
	LSSharedFileListRef items =
    LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, NULL);
  
	if (!items)
	{
		return;
	}
	
	CFStringRef path = CFStringCreateWithCString(kCFAllocatorDefault, cpath, kCFStringEncodingUTF8);
	CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path, kCFURLPOSIXPathStyle, false);	
	LSSharedFileListItemRef item =
    LSSharedFileListInsertItemURL(items, kLSSharedFileListItemLast, NULL, NULL, url, NULL, NULL);
	
	CFRelease(items);
	CFRelease(path);
	CFRelease(url);
	if (item)
	{
		CFRelease(item);
	}
}
开发者ID:ataranto,项目名称:tepeyac,代码行数:24,代码来源:LSSharedFileList.c


示例5: 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


示例6: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ LSSharedFileListItemRemove函数代码示例发布时间:2022-05-30
下一篇:
C++ LSMessageGetPayload函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap