Example #1
0
void SettingsBase::initApplication()
{
    // Prepare the menu of all modules
    categories = KServiceTypeTrader::self()->query("SystemSettingsCategory");
    modules = KServiceTypeTrader::self()->query("KCModule", "[X-KDE-System-Settings-Parent-Category] != ''");
    modules += KServiceTypeTrader::self()->query("SystemSettingsExternalApp");
    rootModule = new MenuItem( true, 0 );
    initMenuList(rootModule);
    // Handle lost+found modules...
    if (lostFound) {
        for (int i = 0; i < modules.size(); ++i) {
            const KService::Ptr entry = modules.at(i);
            MenuItem * infoItem = new MenuItem(false, lostFound);
            infoItem->setService( entry );
            qDebug() << "Added " << entry->name();
        }
    }

    // Prepare the Base Data
    BaseData::instance()->setMenuItem( rootModule );
    // Load all possible views
    const KService::List pluginObjects = KServiceTypeTrader::self()->query( "SystemSettingsView" );
    const int nbPlugins = pluginObjects.count();
    for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) {
        KService::Ptr activeService = pluginObjects.at( pluginsDone );
        QString error;
        BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error);
        if( error.isEmpty() ) {
            possibleViews.insert( activeService->library(), controller );
            controller->init( activeService );
            connect(controller, SIGNAL(changeToolBarItems(BaseMode::ToolBarItems)), this, SLOT(changeToolBar(BaseMode::ToolBarItems)));
            connect(controller, SIGNAL(actionsChanged()), this, SLOT(updateViewActions()));
            connect(searchText, SIGNAL(textChanged(QString)), controller, SLOT(searchChanged(QString)));
            connect(controller, SIGNAL(viewChanged(bool)), this, SLOT(viewChange(bool)));
        } else {
bool Helper::handleReveal()
    {
    if( !readArguments( 1 ))
        return false;
    QString path = getArgument();
    if( !allArgumentsUsed())
        return false;
    //KApplication::updateUserTimestamp( 0 ); // TODO
    const KService::List apps = KMimeTypeTrader::self()->query("inode/directory", "Application");
    if (apps.size() != 0)
        {
        QString command = apps.at(0)->exec().split( " " ).first(); // only the actual command
        if (command == "dolphin" || command == "konqueror")
            {
            command = QStandardPaths::findExecutable(command);
            if( command.isEmpty())
                return false;
            return KProcess::startDetached(command, QStringList() << "--select" << path);
            }
        }
    QFileInfo info(path);
    QString dir = info.dir().path();
    (void) new KRun( QUrl::fromLocalFile(dir), NULL ); // TODO parent
    return true; // TODO check for errors?
    }
Example #3
0
STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
{
    TCHAR   szFileUserClickedOn[MAX_PATH];
    TCHAR   dllPath[MAX_PATH];
    QString command;

    FORMATETC fmte = {
        CF_HDROP,
        (DVTARGETDEVICE FAR *)NULL,
        DVASPECT_CONTENT,
        -1,
        TYMED_HGLOBAL
    };

    GetModuleFileName(_hModule, dllPath, MAX_PATH);
    QString module = lptstr2QString(dllPath);
    command += module.left(module.lastIndexOf('\\'));
    command += '\\';

    for (unsigned i = 0; i < m_cbFiles; i++) {
        DragQueryFile((HDROP)m_stgMedium.hGlobal, i, szFileUserClickedOn, MAX_PATH);
        QString path = lptstr2QString(szFileUserClickedOn);
        
        if(0 == i)
        {
            KMimeType::Ptr ptr = KMimeType::findByPath(path);

            KService::List lst = KMimeTypeTrader::self()->query(ptr->name(), "Application");

            if(lst.size() > 0)
            {
                QString exec = lst.at(0)->exec();
                if( -1 != exec.indexOf("%u", 0, Qt::CaseInsensitive) )
                {
                    exec = exec.left(exec.indexOf("%u", 0, Qt::CaseInsensitive));
                }            
                command += exec;
            }
        };
        
        command += "\"" + path + "\"";
    }

    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_RESTORE;
    if (!CreateProcess(NULL, (LPTSTR)command.utf16(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
        MessageBox(lpcmi->hwnd,
                   TEXT("Error creating process: kdecm.dll needs to be in the same directory as the executable"),
                   TEXT("KDE Extension"),
                   MB_OK);
    }

    return NOERROR;
}
Example #4
0
bool PlacesModel::activityLinkingEnabled()
{
    const KService::List services = KServiceTypeTrader::self()->query(QStringLiteral("KFileItemAction/Plugin"),
        QStringLiteral("Library == 'kactivitymanagerd_fileitem_linking_plugin'"));

    if (services.isEmpty()) {
        return false;
    }

    return !services.at(0).data()->noDisplay();
}
Example #5
0
/**
 * @todo enable delegates again
 */
QAbstractItemDelegate* payeeIdentifierLoader::createItemDelegate(const QString& payeeIdentifierId, QObject* parent)
{
  /** @todo escape ' in  payeeIdentifierId */
  KService::List offers = KServiceTypeTrader::self()->query(QLatin1String("KMyMoney/PayeeIdentifierDelegate"), QString("'%1' ~in [X-KMyMoney-payeeIdentifierIds]").arg(payeeIdentifierId));
  if (!offers.isEmpty()) {
    QString error;
    QAbstractItemDelegate* ptr = offers.at(0)->createInstance<QAbstractItemDelegate>(parent, QVariantList(), &error);
    if (ptr == nullptr) {
      qWarning() << "could not load delegate" << error << payeeIdentifierId;
    }
    return ptr;
  }
  return nullptr;
}
Example #6
0
STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
    UINT idCmd = idCmdFirst;
    BOOL bAppendItems=TRUE;
    TCHAR szFileUserClickedOn[MAX_PATH];

    FORMATETC fmte = {
        CF_HDROP,
        (DVTARGETDEVICE FAR *)NULL,
        DVASPECT_CONTENT,
        -1,
        TYMED_HGLOBAL
    };

    HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium);

    if (SUCCEEDED(hres)) {
        if (m_stgMedium.hGlobal)
            m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0);
            qDebug() << "number of files:" << m_cbFiles;
            for (unsigned i = 0; i < m_cbFiles; i++) {
                DragQueryFile((HDROP)m_stgMedium.hGlobal, i, szFileUserClickedOn, MAX_PATH);
                qDebug() << "file to open:" << lptstr2QString(szFileUserClickedOn);
            }
    }
    QString path = lptstr2QString(szFileUserClickedOn);

    UINT nIndex = indexMenu++;
    
    KMimeType::Ptr ptr = KMimeType::findByPath(path);

    KService::List lst = KMimeTypeTrader::self()->query(ptr->name(), "Application");
    
    if(lst.size() > 0)
    {
        TCHAR str[256];
        wsprintf(str, TEXT("Open with %s"), (LPTSTR)lst.at(0)->name().utf16());
        InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, str );

        if (m_hKdeLogoBmp) {
            SetMenuItemBitmaps(hMenu, nIndex, MF_BYPOSITION, m_hKdeLogoBmp, m_hKdeLogoBmp);
        }
    }

    return ResultFromShort(idCmd-idCmdFirst);
}
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
void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab)
{
    if (!m_uaTab.isNull())
    {
        disconnect(this, SIGNAL(reloadTab()), m_uaTab.data()->view(), SLOT(reload()));
        m_uaTab.clear();
    }

    m_uaTab = uaTab;
    connect(this, SIGNAL(reloadTab()), m_uaTab.data()->view(), SLOT(reload()));

    bool defaultUA = true;

    QAction *a, *defaultAction;

    // just to be sure...
    uaMenu->clear();

    defaultAction = new QAction(i18nc("Default rekonq user agent", "Default"), uaMenu);
    defaultAction->setData(-1);
    defaultAction->setCheckable(true);
    connect(defaultAction, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));

    uaMenu->addAction(defaultAction);
    uaMenu->addSeparator();

    // Main Browsers Menus
    KMenu *ffMenu = new KMenu(i18n("Firefox"), uaMenu);
    uaMenu->addMenu(ffMenu);

    KMenu *ieMenu = new KMenu(i18n("Internet Explorer"), uaMenu);
    uaMenu->addMenu(ieMenu);

    KMenu *nsMenu = new KMenu(i18n("Netscape"), uaMenu);
    uaMenu->addMenu(nsMenu);

    KMenu *opMenu = new KMenu(i18n("Opera"), uaMenu);
    uaMenu->addMenu(opMenu);

    KMenu *sfMenu = new KMenu(i18n("Safari"), uaMenu);
    uaMenu->addMenu(sfMenu);

    KMenu *otMenu = new KMenu(i18n("Other"), uaMenu);
    uaMenu->addMenu(otMenu);

    UserAgentInfo uaInfo;
    QStringList UAlist = uaInfo.availableUserAgents();
    const KService::List providers = uaInfo.availableProviders();
    int uaIndex = uaInfo.uaIndexForHost(m_uaTab.data()->url().host());

    for (int i = 0; i < UAlist.count(); ++i)
    {
        QString uaDesc = UAlist.at(i);

        a = new QAction(uaDesc, uaMenu);
        a->setData(i);
        a->setCheckable(true);
        connect(a, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));

        if (i == uaIndex)
        {
            a->setChecked(true);
            defaultUA = false;
        }

        QString tag = providers.at(i)->property("X-KDE-UA-TAG").toString();
        if (tag == QL1S("FF"))
        {
            ffMenu->addAction(a);
        }
        else if (tag == QL1S("IE"))
        {
            ieMenu->addAction(a);
        }
        else if (tag == QL1S("NN"))
        {
            nsMenu->addAction(a);
        }
        else if (tag == QL1S("OPR"))
        {
            opMenu->addAction(a);
        }
        else if (tag == QL1S("SAF"))
        {
            sfMenu->addAction(a);
        }
        else    // OTHERs
        {
            otMenu->addAction(a);
        }
    }
    defaultAction->setChecked(defaultUA);

    uaMenu->addSeparator();
    uaMenu->addAction(m_uaSettingsAction);
}