Example #1
0
QString KProtocolInfo::exec(const QString& protocol)
{
  KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(protocol);

  // We have up to two sources of data:
  // 1) the exec line of the .protocol file, if there's one (could be a kioslave or a helper app)
  // 2) the application associated with x-scheme-handler/<protocol> if there's one

  // If both exist, then:
  //  A) if the .protocol file says "launch an application", then the new-style handler-app has priority
  //  B) but if the .protocol file is for a kioslave (e.g. kio_http) then this has priority over
  //     firefox or chromium saying x-scheme-handler/http. Gnome people want to send all HTTP urls
  //     to a webbrowser, but we want mimetype-determination-in-calling-application by default
  //     (the user can configure a BrowserApplication though)

  QString helperExe;
  const KService::Ptr service = KMimeTypeTrader::self()->preferredService(QString::fromLatin1("x-scheme-handler/") + protocol);
  if (service) {
      helperExe = service->exec();
      if (prot && prot->m_isHelperProtocol)
          return helperExe; // for helper protocols, the handler app has priority over the hardcoded one (see A above)
  }
  if (prot) {
      return prot->m_exec;
  }

  // If there's no protocol file, then return the handler app if any, otherwise empty string
  return helperExe;
}
bool Helper::handleAppsDialog()
    {
    if( !readArguments( 1 ))
        return false;
    QString title = getArgument();
    long wid = getArgumentParent();
    if( !allArgumentsUsed())
        return false;
    KOpenWithDialog dialog( NULL );
    if( !title.isEmpty())
        dialog.setWindowTitle( title );
    dialog.hideNoCloseOnExit();
    dialog.hideRunInTerminal(); // TODO
    if( wid != 0 )
        KWindowSystem::setMainWindow( &dialog, wid );
    if( dialog.exec())
        {
        KService::Ptr service = dialog.service();
        QString command;
        if( service )
            command = service->exec();
        else if( !dialog.text().isEmpty())
            command = dialog.text();
        else
            return false;
        command = command.split( " " ).first(); // only the actual command
        command = QStandardPaths::findExecutable(command);
        if( command.isEmpty())
            return false;
        outputLine( QUrl::fromUserInput( command ).url());
        return true;
        }
    return false;
    }
bool
EngineController::installDistroCodec()
{
    KService::List services = KServiceTypeTrader::self()->query( "Amarok/CodecInstall"
        , QString( "[X-KDE-Amarok-codec] == 'mp3' and [X-KDE-Amarok-engine] == 'phonon-%1'").arg( "xine" ) );
    //todo - figure out how to query Phonon for the current backend loaded
    if( !services.isEmpty() )
    {
        KService::Ptr service = services.first(); //list is not empty
        QString installScript = service->exec();
        if( !installScript.isNull() ) //just a sanity check
        {
            KGuiItem installButton( i18n( "Install MP3 Support" ) );
            if(KMessageBox::questionYesNo( The::mainWindow()
            , i18n("Amarok currently cannot play MP3 files. Do you want to install support for MP3?")
            , i18n( "No MP3 Support" )
            , installButton
            , KStandardGuiItem::no()
            , "codecInstallWarning" ) == KMessageBox::Yes )
            {
                    KRun::runCommand(installScript, 0);
                    return true;
            }
        }
    }

    return false;
}
Example #4
0
static bool isMimeTypeAssociatedWithSelf(const KService::Ptr &offer)
{
    if (!offer)
        return false;

    kDebug(800) << offer->desktopEntryName();

    const QString& appName = QCoreApplication::applicationName();

    if (appName == offer->desktopEntryName() || offer->exec().trimmed().startsWith(appName))
        return true;

    // konqueror exception since it uses kfmclient to open html content...
    if (appName == QL1S("konqueror") && offer->exec().trimmed().startsWith(QL1S("kfmclient")))
        return true;

    return false;
}
QString BookmarksRunner::findBrowserName()
{
    //HACK find the default browser
    KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") );
    QString exec = config.readPathEntry(QStringLiteral("BrowserApplication"), QString());
    //qDebug() << "Found exec string: " << exec;
    if (exec.isEmpty()) {
        KService::Ptr service = KMimeTypeTrader::self()->preferredService(QStringLiteral("text/html"));
        if (service) {
            exec = service->exec();
        }
    }

    //qDebug() << "KRunner::Bookmarks: found executable " << exec << " as default browser";
    return exec;

}
Example #6
0
/*
* 接受isoftappdaemon finished 信号
* 1.更新所有包列表中对应包的状态
* 2.给每个页面发送taskfinished信号
* 3.更新taskqueue队列:
*   a、删除当前任务
*   b、开始新任务
*/
void JadedBus::getFinished(const QString &pkgName,qlonglong status)
{
    if (status != STATUS_REMOVED &&
        status != STATUS_UPDATED &&
        status != STATUS_INSTALLED &&
        status != STATUS_INSTALL &&
        status != STATUS_UPGRADED &&
        status != STATUS_INSTALL_ERROR) {
        return;
    }

    if(pkgName.isEmpty()) {
        return;
    }

    int i =0;
    for (i = 0; i < AllPkgList.size(); ++i) {
        if (AllPkgList.at(i).pkgName  == pkgName) {
            if (status == STATUS_INSTALLED) {
                if (AllPkgList[i].status != 1) {
                    AllPkgList[i].status = 1;
                    QDateTime local(QDateTime::currentDateTime());
                    AllPkgList[i].datetime = local.toString("yyyy-MM-dd hh:mm:ss");

                    QString desktopName = m_isoftapp->GetDesktopName(pkgName).value();
                    if (!desktopName.isEmpty())
                        desktopName = desktopName.left(desktopName.size() - 8);
                    KService::Ptr service = KService::serviceByDesktopName(desktopName);
                    if (!service) {
                        service = KService::serviceByDesktopName(pkgName);
                    }
                    if (service) {
                        if (!service->exec().isEmpty() && !service->noDisplay()) {
                            QFile::link(service->entryPath(),
                                QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) +
                                "/" + service->name() + ".desktop");
                        }
                    }
                }

            } else if (status == STATUS_REMOVED) {
                if (AllPkgList[i].status != 2) {
                    AllPkgList[i].status = 2;
                    QDateTime local(QDateTime::currentDateTime());
                    AllPkgList[i].datetime = local.toString("yyyy-MM-dd hh:mm:ss");
                }
            } else if ( status == STATUS_INSTALL_ERROR) {
                if (AllPkgList[i].status != 2) {
                    AllPkgList[i].status = 2;
                }
                QString details ="insatallfailed";
                m_errored(pkgName,details);
            }
            getMyPkgNumber();

            break;
        }
    }

    taskFinished(pkgName);

    for (i = 0; i < m_taskQueue.size(); i++) {
        if (m_taskQueue[i].status == "doing" &&
            pkgName == m_taskQueue[i].name) {
            if (m_taskQueue[i].action == "update") {
                int t = (int)time(NULL);
                m_updateInfo.replace(pkgName,QString::number(t, 10));
                //getUpdate() ;
            }
            printf("trace:%s,%d,name[%s],index[%d][%s] task is finished.\n",__FUNCTION__,__LINE__,
                   qPrintable(m_taskQueue[i].name),i,qPrintable(m_taskQueue[i].action));
            m_taskQueue[i].status = "done";
            g_doingPkgName = "";
            m_taskQueue.removeFirst();
            m_runTask();
            return;
        }
    }

    return;
}
Example #7
0
int main(int argc, char *argv[])
{
	KCmdLineArgs::init(argc, argv, appName, "kscreensaver", ki18n("Random screen saver"), 
                KDE_VERSION_STRING, ki18n(description));


	KCmdLineOptions options;

	options.add("setup", ki18n("Setup screen saver"));

	options.add("window-id wid", ki18n("Run in the specified XWindow"));

	options.add("root", ki18n("Run in the root XWindow"));

	KCmdLineArgs::addCmdLineOptions(options);

	KApplication app;

	WId windowId = 0;

	KCmdLineArgs *args = KCmdLineArgs::parsedArgs();

	if (args->isSet("setup"))
	{
		KRandomSetup setup;
		setup.exec();
		exit(0);
	}

	if (args->isSet("window-id"))
	{
		windowId = args->getOption("window-id").toInt();
	}

#ifdef Q_WS_X11
	if (args->isSet("root"))
	{
		QX11Info info;
		windowId = RootWindow(QX11Info::display(), info.screen());
	}
#endif
	args->clear();
	const KService::List lst = KServiceTypeTrader::self()->query( "ScreenSaver");
        KService::List availableSavers;

	KConfig type("krandom.kssrc", KConfig::NoGlobals);
        const KConfigGroup configGroup = type.group("Settings");
	const bool opengl = configGroup.readEntry("OpenGL", false);
	const bool manipulatescreen = configGroup.readEntry("ManipulateScreen", false);
        // TODO replace this with TryExec=fortune in the desktop files
        const bool fortune = !KStandardDirs::findExe("fortune").isEmpty();
        foreach( const KService::Ptr& service, lst ) {
            //QString file = KStandardDirs::locate("services", service->entryPath());
            //kDebug() << "Looking at " << file;
            const QString saverType = service->property("X-KDE-Type").toString();
            foreach (const QString &type, saverType.split(QLatin1Char(';'))) {
                //kDebug() << "saverTypes is "<< type;
                if (type == QLatin1String("ManipulateScreen")) {
                    if (!manipulatescreen)
                        goto fail;
                } else if (type == QLatin1String("OpenGL")) {
                    if (!opengl)
                        goto fail;
                } else if (type == QLatin1String("Fortune")) {
                    if (!fortune)
                        goto fail;
                }
            }
            availableSavers.append(service);
          fail: ;
        }

	KRandomSequence rnd;
	const int indx = rnd.getLong(availableSavers.count());
        const KService::Ptr service = availableSavers.at(indx);
        const QList<KServiceAction> actions = service->actions();

	QString cmd;
	if (windowId)
            cmd = exeFromActionGroup(actions, "InWindow");
        if (cmd.isEmpty() && windowId == 0)
            cmd = exeFromActionGroup(actions, "Root");
        if (cmd.isEmpty())
            cmd = service->exec();

    QHash<QChar, QString> keyMap;
    keyMap.insert('w', QString::number(windowId));
    const QStringList words = KShell::splitArgs(KMacroExpander::expandMacrosShellQuote(cmd, keyMap));
    if (!words.isEmpty()) {
        QString exeFile = KStandardDirs::findExe(words.first());
        if (!exeFile.isEmpty()) {
            char **sargs = new char *[words.size() + 1];
            int i = 0;
            for (; i < words.size(); i++)
                sargs[i] = qstrdup(words[i].toLocal8Bit().constData());
            sargs[i] = 0;

            execv(exeFile.toLocal8Bit(), sargs);
        }
    }

	// If we end up here then we couldn't start a saver.
	// If we have been supplied a window id or root window then blank it.
#ifdef Q_WS_X11
	QX11Info info;
	Window win = windowId ? windowId : RootWindow(QX11Info::display(), info.screen());
	XSetWindowBackground(QX11Info::display(), win,
			BlackPixel(QX11Info::display(), info.screen()));
	XClearWindow(QX11Info::display(), win);
#endif
}
Example #8
0
QVariant AppsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() >= m_entryList.count()) {
        return QVariant();
    }

    const AbstractEntry *entry = m_entryList.at(index.row());

    if (role == Qt::DisplayRole) {
        return entry->name();
    } else if (role == Qt::DecorationRole) {
        return entry->icon();
    } else if (role == Kicker::IsParentRole) {
        return (entry->type() == AbstractEntry::GroupType);
    } else if (role == Kicker::HasChildrenRole) {
        if (entry->type() == AbstractEntry::GroupType) {
            const AbstractGroupEntry *groupEntry = static_cast<const AbstractGroupEntry *>(entry);

            if (groupEntry->model() && groupEntry->model()->count()) {
                return true;
            }
        }
    } else if (role == Kicker::FavoriteIdRole) {
        if (entry->type() == AbstractEntry::RunnableType) {
            return QVariant("app:" + static_cast<AppEntry *>(m_entryList.at(index.row()))->service()->storageId());
        }
    } else if (role == Kicker::HasActionListRole) {
        if (entry->type() == AbstractEntry::RunnableType || !m_hiddenEntries.isEmpty()) {
            return true;
        } else if (entry->type() == AbstractEntry::GroupType) {
            const AbstractGroupEntry *groupEntry = static_cast<const AbstractGroupEntry *>(entry);

            if (groupEntry->model()) {
                const AppsModel *appsModel = qobject_cast<const AppsModel *>(groupEntry->model());

                if (appsModel && !appsModel->hiddenEntries().isEmpty()) {
                    return true;
                }
            }
        }
    } else if (role == Kicker::ActionListRole) {
        QVariantList actionList;

        if (entry->type() == AbstractEntry::RunnableType) {
            const KService::Ptr service = static_cast<const AppEntry *>(entry)->service();

            if (ContainmentInterface::mayAddLauncher(m_appletInterface, ContainmentInterface::Desktop)) {
                actionList << Kicker::createActionItem(i18n("Add to Desktop"), "addToDesktop");
            }

            if (ContainmentInterface::mayAddLauncher(m_appletInterface, ContainmentInterface::Panel)) {
                actionList << Kicker::createActionItem(i18n("Add to Panel"), "addToPanel");
            }

            if (ContainmentInterface::mayAddLauncher(m_appletInterface, ContainmentInterface::TaskManager, service->entryPath())) {
                actionList << Kicker::createActionItem(i18n("Add as Launcher"), "addToTaskManager");
            }

            if (m_menuEntryEditor->canEdit(service->entryPath())) {
                actionList << Kicker::createSeparatorActionItem();

                QVariantMap editAction = Kicker::createActionItem(i18n("Edit Application..."), "editApplication");
                editAction["icon"] = "kmenuedit"; // TODO: Using the KMenuEdit icon might be misleading.
                actionList << editAction;
            }

#ifdef PackageKitQt5_FOUND
            QStringList files(service->entryPath());

            if (service->isApplication()) {
                files += QStandardPaths::findExecutable(KShell::splitArgs(service->exec()).first());
            }

            FindPackageJob* job = new FindPackageJob(files); // TODO: Would be great to make this async.

            if (job->exec() && !job->packageNames().isEmpty()) {
                QString packageName = job->packageNames().first();

                QVariantMap removeAction = Kicker::createActionItem(i18n("Remove '%1'...", packageName), "removeApplication", packageName);
                removeAction["icon"] = "applications-other";
                actionList << removeAction;
            }
#endif

            if (appletConfig() && appletConfig()->contains("hiddenApplications")) {
                const QStringList &hiddenApps = appletConfig()->value("hiddenApplications").toStringList();

                if (!hiddenApps.contains(service->menuId())) {
                    actionList << Kicker::createActionItem(i18n("Hide Application"), "hideApplication");
                }
            }
        }

        if (!m_hiddenEntries.isEmpty()) {
            actionList << Kicker::createSeparatorActionItem();
            actionList << Kicker::createActionItem(i18n("Unhide Applications in this Submenu"), "unhideSiblingApplications");
        }

        if (entry->type() == AbstractEntry::GroupType) {
            const AbstractGroupEntry *groupEntry = static_cast<const AbstractGroupEntry *>(entry);

            if (groupEntry->model()) {
                const AppsModel *appsModel = qobject_cast<const AppsModel *>(groupEntry->model());

                if (appsModel && !appsModel->hiddenEntries().isEmpty()) {
                    actionList << Kicker::createActionItem(i18n("Unhide Applications in '%1'", entry->name()), "unhideChildApplications");
                }
            }
        }

        return actionList;
    } else if (role == Kicker::UrlRole) {
        if (entry->type() == AbstractEntry::RunnableType) {
            return QUrl::fromLocalFile(static_cast<AppEntry *>(m_entryList.at(index.row()))->service()->entryPath());
        }
    }

    return QVariant();
}
Example #9
0
void Wizard::slotCheckPrograms()
{
    QSize itemSize(20, fontMetrics().height() * 2.5);
    m_check.programList->setColumnWidth(0, 30);
    m_check.programList->setIconSize(QSize(24, 24));

    QTreeWidgetItem *item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("FFmpeg & ffplay"));
    item->setData(1, Qt::UserRole, i18n("Required for webcam capture"));
    item->setSizeHint(0, itemSize);
    QString exepath = KStandardDirs::findExe("ffmpeg");
    if (exepath.isEmpty()) item->setIcon(0, m_badIcon);
    else if (KStandardDirs::findExe("ffplay").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

#ifndef Q_WS_MAC
    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("recordmydesktop"));
    item->setData(1, Qt::UserRole, i18n("Required for screen capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("recordmydesktop").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvgrab"));
    item->setData(1, Qt::UserRole, i18n("Required for firewire capture"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvgrab").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);
#endif

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("dvdauthor"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("dvdauthor").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);


    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("genisoimage or mkisofs"));
    item->setData(1, Qt::UserRole, i18n("Required for creation of DVD ISO images"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("genisoimage").isEmpty()) {
        // no GenIso, check for mkisofs
        if (!KStandardDirs::findExe("mkisofs").isEmpty()) {
            item->setIcon(0, m_okIcon);
        } else item->setIcon(0, m_badIcon);
    } else item->setIcon(0, m_okIcon);

    item = new QTreeWidgetItem(m_check.programList, QStringList() << QString() << i18n("xine"));
    item->setData(1, Qt::UserRole, i18n("Required to preview your DVD"));
    item->setSizeHint(0, itemSize);
    if (KStandardDirs::findExe("xine").isEmpty()) item->setIcon(0, m_badIcon);
    else item->setIcon(0, m_okIcon);

    // set up some default applications
    QString program;
    if (KdenliveSettings::defaultimageapp().isEmpty()) {
        program = KStandardDirs::findExe("gimp");
        if (program.isEmpty()) program = KStandardDirs::findExe("krita");
        if (!program.isEmpty()) KdenliveSettings::setDefaultimageapp(program);
    }
    if (KdenliveSettings::defaultaudioapp().isEmpty()) {
        program = KStandardDirs::findExe("audacity");
        if (program.isEmpty()) program = KStandardDirs::findExe("traverso");
        if (!program.isEmpty()) KdenliveSettings::setDefaultaudioapp(program);
    }
    if (KdenliveSettings::defaultplayerapp().isEmpty()) {
        KService::Ptr offer = KMimeTypeTrader::self()->preferredService("video/mpeg");
        if (offer)
            KdenliveSettings::setDefaultplayerapp(KRun::binaryName(offer->exec(), true));
    }
}
Example #10
0
void PortListener::loadConfig(KService::Ptr s) {
	m_valid = true;
	m_autoPortRange = 0;
	m_enabled = true;
	m_argument = QString::null;
	m_multiInstance = false;

	QVariant vid, vport, vautoport, venabled, vargument, vmultiInstance, vurl,
	  vsattributes, vslifetime, vdname, vdtype, vddata;

	m_execPath = s->exec().utf8();
	vid = s->property("X-KDE-KINETD-id");
	vport = s->property("X-KDE-KINETD-port");
	vautoport = s->property("X-KDE-KINETD-autoPortRange");
	venabled = s->property("X-KDE-KINETD-enabled");
	vargument = s->property("X-KDE-KINETD-argument");
	vmultiInstance = s->property("X-KDE-KINETD-multiInstance");
	vurl = s->property("X-KDE-KINETD-serviceURL");
	vsattributes = s->property("X-KDE-KINETD-serviceAttributes");
	vslifetime = s->property("X-KDE-KINETD-serviceLifetime");
	vdname = s->property("X-KDE-KINETD-DNSSD-Name");
	vdtype = s->property("X-KDE-KINETD-DNSSD-Type");
	vddata = s->property("X-KDE-KINETD-DNSSD-Properties");

	if (!vid.isValid()) {
		kdDebug() << "Kinetd cannot load service "<<m_serviceName
			  <<": no id set" << endl;
		m_valid = false;
		return;
	}

	if (!vport.isValid()) {
		kdDebug() << "Kinetd cannot load service "<<m_serviceName
			  <<": invalid port" << endl;
		m_valid = false;
		return;
	}

	m_serviceName = vid.toString();
	m_serviceLifetime = vslifetime.toInt();
	if (m_serviceLifetime < 120) // never less than 120 s
		m_serviceLifetime = 120;
	m_portBase = vport.toInt();
	if (vautoport.isValid())
		m_autoPortRange = vautoport.toInt();
	if (venabled.isValid())
		m_enabled = venabled.toBool();
	if (vargument.isValid())
		m_argument = vargument.toString();
	if (vmultiInstance.isValid())
		m_multiInstance = vmultiInstance.toBool();
	if (vurl.isValid()) {
		m_serviceURL = vurl.toString();
		m_registerService = true;
	}
	else {
		m_serviceURL = QString::null;
		m_registerService = false;
	}
	if (vsattributes.isValid()) {
		m_serviceAttributes = vsattributes.toString();
	}
	else
		m_serviceAttributes = "";
	if (vddata.isValid()) {
		QStringList attrs = vddata.toStringList();
		for (QStringList::iterator it=attrs.begin();
		it!=attrs.end();it++) {
		    QString key = (*it).section('=',0,0);
		    QString value =  processServiceTemplate((*it).section('=',1))[0];
		    if (!key.isEmpty()) m_dnssdData[key]=value;
		    }
	}
	if (vdname.isValid() && vdtype.isValid()) {
		m_dnssdName = processServiceTemplate(vdname.toString())[0];
		m_dnssdType = vdtype.toString();
		m_dnssdRegister = true;
		kdDebug() << "DNS-SD register is enabled\n";
	}
	else 
	        m_dnssdRegister = false;
		

	m_slpLifetimeEnd = QDateTime::currentDateTime().addSecs(m_serviceLifetime);
	m_defaultPortBase = m_portBase;
	m_defaultAutoPortRange = m_autoPortRange;

	m_config->setGroup("ListenerConfig");
	m_enabled = m_config->readBoolEntry("enabled_" + m_serviceName,
					    m_enabled);
	m_portBase = m_config->readNumEntry("port_base_" + m_serviceName,
					    m_portBase);
	m_autoPortRange = m_config->readNumEntry("auto_port_range_" + m_serviceName,
						 m_autoPortRange);
	QDateTime nullTime;
	m_expirationTime = m_config->readDateTimeEntry("enabled_expiration_"+m_serviceName,
						     &nullTime);
	if ((!m_expirationTime.isNull()) && (m_expirationTime < QDateTime::currentDateTime()))
		m_enabled = false;
	m_registerService = m_config->readBoolEntry("enabled_srvreg_"+m_serviceName,
						     m_registerService);
}