本文整理汇总了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
}
示例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;
}
示例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
}
示例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);
//.........这里部分代码省略.........