void LXQtQuickLaunch::dropEvent(QDropEvent *e)
{
    const QMimeData *mime = e->mimeData();

    foreach (const QUrl &url, mime->urls().toSet())
    {
        QString fileName(url.isLocalFile() ? url.toLocalFile() : url.url());
        QFileInfo fi(fileName);
        XdgDesktopFile xdg;

        if (xdg.load(fileName))
        {
            if (xdg.isSuitable())
                addButton(new QuickLaunchAction(&xdg, this));
        }
        else if (fi.exists() && fi.isExecutable() && !fi.isDir())
        {
            addButton(new QuickLaunchAction(fileName, fileName, "", this));
        }
        else if (fi.exists())
        {
            addButton(new QuickLaunchAction(fileName, this));
        }
        else
        {
            qWarning() << "XdgDesktopFile" << fileName << "is not valid";
            QMessageBox::information(this, tr("Drop Error"),
                              tr("File/URL '%1' cannot be embedded into QuickLaunch for now").arg(fileName)
                            );
        }
    }
    saveSettings();
}
示例#2
0
XdgAction::XdgAction(const QString& desktopFileName, QObject *parent):
    QAction(parent)
{
    XdgDesktopFile df;
    df.load(desktopFileName);
    load(df);
}
示例#3
0
RazorConfig::MainWindow::MainWindow() : QMainWindow()
{
    setupUi(this);
        
    qDebug() << "Reading desktop files from dir:" << RAZOR_CONFIG_MODULES_DIR;
    
    QDirIterator it(RAZOR_CONFIG_MODULES_DIR, QStringList() << "*.desktop");
    int ix = 0;
    QString name;

    while (it.hasNext()) {
        name = it.next();
        XdgDesktopFile *xdg = new XdgDesktopFile();
        xdg->load(name);
        if (!xdg->isValid())
        {
            qDebug() << "INVALID DESKTOP FILE:" << name;
            delete xdg;
            continue;
        }
        
        new ConfigItem(xdg, listWidget);

        ++ix;
    }
    
    if (listWidget->count() == 0)
        statusBar()->showMessage(tr("No config modules found in: ") + RAZOR_CONFIG_MODULES_DIR);
    
    connect(listWidget, SIGNAL(itemActivated(QListWidgetItem*)),//SIGNAL(itemDoubleClicked(QListWidgetItem*)),
            this, SLOT(listWidget_itemDoubleClicked(QListWidgetItem *)));
}
示例#4
0
void FileIcon::launchApp()
{
    qDebug() << "FileIcon::launchApp()" << m_file << m_mimeInfo->mimeType();

    XdgDesktopFile* desktopFile = XdgDesktopFileCache::getDefaultApp(m_mimeInfo->mimeType());
    if (desktopFile)
        desktopFile->startDetached(m_file);
}
示例#5
0
bool AppLinkItem::run() const
{
    XdgDesktopFile desktop;
    if (desktop.load(mDesktopFile))
        return desktop.startDetached();
    else
        return false;
}
LXQtQuickLaunch::LXQtQuickLaunch(ILXQtPanelPlugin *plugin, QWidget* parent) :
    QFrame(parent),
    mPlugin(plugin),
    mPlaceHolder(0)
{
    setAcceptDrops(true);

    mLayout = new LXQt::GridLayout(this);
    setLayout(mLayout);

    QString desktop;
    QString file;
    QString execname;
    QString exec;
    QString icon;
    for (const QMap<QString, QVariant> &app : mPlugin->settings()->readArray("apps"))
    {
        desktop = app.value("desktop", "").toString();
        file = app.value("file", "").toString();
        if (!desktop.isEmpty())
        {
            XdgDesktopFile xdg;
            if (!xdg.load(desktop))
            {
                qDebug() << "XdgDesktopFile" << desktop << "is not valid";
                continue;
            }
            if (!xdg.isSuitable())
            {
                qDebug() << "XdgDesktopFile" << desktop << "is not applicable";
                continue;
            }

            addButton(new QuickLaunchAction(&xdg, this));
        }
        else if (! file.isEmpty())
        {
            addButton(new QuickLaunchAction(file, this));
        }
        else
        {
            execname = app.value("name", "").toString();
            exec = app.value("exec", "").toString();
            icon = app.value("icon", "").toString();
            if (icon.isNull())
            {
                qDebug() << "Icon" << icon << "is not valid (isNull). Skipped.";
                continue;
            }
            addButton(new QuickLaunchAction(execname, exec, icon, this));
        }
    } // for

    if (mLayout->isEmpty())
        showPlaceHolder();

    realign();
}
示例#7
0
void XdgAutoStart::debugAutostart()
{
    for (int i = 0; i < m_list.count(); i++)
    {
        XdgDesktopFile * tmp = m_list.at(i);
        qDebug() << tmp->value("Name").toString();
    }

}
示例#8
0
void XdgCachedMenu::onItemTrigerred()
{
    XdgCachedMenuAction* action = static_cast<XdgCachedMenuAction*>(sender());
    XdgDesktopFile df;
    char* desktop_file = menu_cache_item_get_file_path(action->item());
    df.load(desktop_file);
    g_free(desktop_file);
    df.startDetached();
}
示例#9
0
void AutostartItem::setEnabled(bool enable)
{
    XdgDesktopFile f = file();
    if (enable)
        f.removeEntry("Hidden");
    else
        f.setValue("Hidden", true);

    setLocal(f);
}
示例#10
0
/**
 * @brief does clean the list according to the XDG-Standards
 */
void XdgAutoStart::cleanList()
{
    qDebug() << "XdgAutoStart: cleaning house! (" << badNames.count() << " bad Names )";
    for (int i = 0; i < m_list.count(); i++)
    {
        XdgDesktopFile * tmp = m_list.at(i);
        if (badNames.contains(tmp->value("Name").toString()))
        {
            delete m_list.takeAt(i);
        }
    }
    qDebug() << "XdgAutoStart: after cleaning: " << m_list.count()<< " items left.";
}
void XdgMenuApplinkProcessor::step2()
{
    // Create AppLinks elements ...........................
    QDomDocument doc = mElement.ownerDocument();

    foreach (XdgMenuAppFileInfo* fileInfo, mSelected)
    {
        if (mOnlyUnallocated && fileInfo->allocated())
            continue;

        XdgDesktopFile* file = fileInfo->desktopFile();

        bool show = false;
        QStringList envs = mMenu->environments();
        const int N = envs.size();
        for (int i = 0; i < N; ++i)
        {
            if (file->isShown(envs.at(i)))
            {
                show = true;
                break;
            }
        }

        if (!show)
            continue;

        QDomElement appLink = doc.createElement(QLatin1String("AppLink"));

        appLink.setAttribute(QLatin1String("id"), fileInfo->id());
        appLink.setAttribute(QLatin1String("title"), file->localizedValue(QLatin1String("Name")).toString());
        appLink.setAttribute(QLatin1String("comment"), file->localizedValue(QLatin1String("Comment")).toString());
        appLink.setAttribute(QLatin1String("genericName"), file->localizedValue(QLatin1String("GenericName")).toString());
        appLink.setAttribute(QLatin1String("exec"), file->value(QLatin1String("Exec")).toString());
        appLink.setAttribute(QLatin1String("terminal"), file->value(QLatin1String("Terminal")).toBool());
        appLink.setAttribute(QLatin1String("startupNoify"), file->value(QLatin1String("StartupNotify")).toBool());
        appLink.setAttribute(QLatin1String("path"), file->value(QLatin1String("Path")).toString());
        appLink.setAttribute(QLatin1String("icon"), file->value(QLatin1String("Icon")).toString());
        appLink.setAttribute(QLatin1String("desktopFile"), file->fileName());

        mElement.appendChild(appLink);

    }


    // Process childs menus ...............................
    foreach (XdgMenuApplinkProcessor* child, mChilds)
        child->step2();
}
示例#12
0
/**
 * @brief adds a given dir to the autostartlist
 * @param[in] _dir the directory to search for files
 **/
void XdgAutoStart::addDirtoList(const QString & _dir)
{
    qDebug() << "XdgAutoStart: adding "<<_dir << " to list!";
    //this is probably small so no dir-iterator.. just list them and work the list!
    QDir directory(_dir);

    directory.setNameFilters(QStringList() << "*.desktop"); //filter the .desktop files only
    QStringList filelist = directory.entryList();
    for (int i =0; i < filelist.count(); i++)
    {
        XdgDesktopFile * f = new XdgDesktopFile(_dir+filelist.at(i));
        if (f->isShow())
            m_list.append(f);
        else
        {
            badNames.push_back(f->value("Name").toString()); //this is needed as std says all with the same name get removed by one entry with these flags too
            delete f;
        }
    }
}
void QuickLaunchAction::execAction()
{
    QString exec(data().toString());
    qDebug() << "execAction" << exec;
    switch (m_type)
    {
        case ActionLegacy:
            QProcess::startDetached(exec);
            break;
        case ActionXdg:
        {
            XdgDesktopFile * xdg = XdgDesktopFileCache::getFile(exec);
            if (xdg->isValid())
                xdg->startDetached();
            break;
        }
        case ActionFile:
            QDesktopServices::openUrl(QUrl(exec));
            break;
    }
}
示例#14
0
 foreach (const XdgDesktopFile& file, localList)
 {
     QString name = QFileInfo(file.fileName()).fileName();
     if (items.contains(name))
     {
         items[name].setLocal(file, true);
     }
     else
     {
         AutostartItem item;
         item.setLocal(file, true);
         items.insert(name, item);
     }
 }
示例#15
0
    void builGroup(const QDomElement& xml)
    {
        QString category;
        if (! xml.attribute("title").isEmpty())
            category = xml.attribute("title");
        else
            category = xml.attribute("name");

        DomElementIterator it(xml , "AppLink");
        while(it.hasNext())
        {
            QDomElement x = it.next();

            XdgDesktopFile xdg;
            xdg.load(x.attribute("desktopFile"));

            ConfigPane pane;
            pane.id() = xdg.value("Icon").toString();
            pane.category() = category;
            pane.setXdg(xdg);
            m_list.append(pane);
        }
    }
示例#16
0
void AutoStartPage::editButton_clicked()
{
    QModelIndex index = ui->autoStartView->selectionModel()->currentIndex();
    XdgDesktopFile file = mXdgAutoStartModel->desktopFile(index);
    AutoStartEdit edit(file.name(), file.value("Exec").toString(), file.contains("X-LXQt-Need-Tray"));
    if (edit.exec() == QDialog::Accepted)
    {
        file.setLocalizedValue("Name", edit.name());
        file.setValue("Exec", edit.command());
        if (edit.needTray())
            file.setValue("X-LXQt-Need-Tray", true);
        else
            file.removeEntry("X-LXQt-Need-Tray");

        mXdgAutoStartModel->setEntry(index, file, true);
    }
}
示例#17
0
void AutoStartPage::editButton_clicked()
{
    QModelIndex index = ui->autoStartView->selectionModel()->currentIndex();
    XdgDesktopFile* file = mXdgAutoStartModel->desktopFile(index);
    if (!file)
        return;
    AutoStartEdit edit(file->name(), file->value("Exec").toString(), file->contains("X-Razor-Need-Tray"));
    if (edit.exec() == QDialog::Accepted)
    {
        file->setLocalizedValue("Name", edit.name());
        file->setValue("Exec", edit.command());
        if (edit.needTray())
            file->setValue("X-Razor-Need-Tray", true);
        else
            file->removeEntry("X-Razor-Need-Tray");

    }
    mXdgAutoStartModel->setData(index, 0, Qt::UserRole);
}
示例#18
0
void XdgAction::load(const XdgDesktopFile& desktopFile)
{
    mDesktopFile = desktopFile;
    if (mDesktopFile.isValid())
    {
        setText(mDesktopFile.name());
        setToolTip(mDesktopFile.comment());

        setIcon(desktopFile.icon());
        if (icon().isNull())
            setIcon(XdgIcon::fromTheme("application-x-executable"));

        connect(this, SIGNAL(triggered()), this, SLOT(runConmmand()));
    }
    else
    {
        setText("");
        setToolTip("");
        setIcon(QIcon());
    }
}
示例#19
0
bool AppLinkItem::run() const
{
    XdgDesktopFile *desktop = XdgDesktopFileCache::getFile(mDesktopFile);
    return desktop->startDetached();
}
示例#20
0
void RazorDeskManager::updateIconList()
{
    m_fsw->blockSignals(true);

    qDebug() << "updateIconList";
    QDirIterator dirIter(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));

    QStringList tmpList;

    while (dirIter.hasNext())
    {
        dirIter.next();
        QString df(dirIter.filePath());

        // HACK: QDir::NoDotAndDotDot does not work so this fixes it...
        if (df.endsWith("/..") || df.endsWith("/."))
            continue;

        qDebug() << df;
        tmpList.append(df);

        // only non existing icons are created
        if (m_iconList.contains(df))
        {
            qDebug() << "updateIconList REREAD. Skip:" << df;
            continue;
        }

        QPoint pos(0, 0);
        RazorDeskIconBase * idata;

        if (dirIter.filePath().endsWith(".desktop")) //only use .desktop files!
        {
            XdgDesktopFile* tmp = new XdgDesktopFile();
            tmp->load(df);

            if (tmp->isShow())
            {
                idata = new RazorDeskIconDesktop(tmp, pos);
            }
            else
            {
                delete tmp;
                qDebug() << "Desktop file" << df << "isShow==false";
                continue;
            }
        }
        else
        {
            idata = new RazorDeskIconFile(df, pos);
        }
        
        idata->setLaunchMode(m_launchMode);

        connect(idata, SIGNAL(moved(QPoint)), this, SLOT(saveIconState()));
        m_iconList[df] = idata;
    }

    // now remove potentialy deleted icons
    IconMapIterator iter(m_iconList);
    while (iter.hasNext())
    {
        iter.next();
        if (tmpList.contains(iter.key()))
            continue;
        delete m_iconList.take(iter.key());
    }

    qDebug() << "Razordeskmanl: found " << m_iconList.count() << " usable desktop-entries";

    restoreIconState();
    m_fsw->blockSignals(false);
}
示例#21
0
文件: xdg.cpp 项目: Icenowy/Cubway
QVariantMap XdgModule::loadDesktopFile(const QString &fileName){
  QVariantMap result;

  XdgDesktopFile desktop;
  desktop.load(fileName);
  switch(desktop.type()){
  case XdgDesktopFile::UnknownType:
    result["type"] = "unknown";
    break;
  case XdgDesktopFile::ApplicationType:
    result["type"] = "application";
    break;
  case XdgDesktopFile::LinkType:
    result["type"] = "link";
    break;
  case XdgDesktopFile::DirectoryType:
    result["type"] = "directory";
  }
  result["valid"] = desktop.isValid();
  result["categories"] = desktop.categories();
  result["icon"] = desktop.icon().pixmap(icon_size, icon_size);
  result["icon_name"] = desktop.iconName();
  result["name"] = desktop.name();
  result["comment"] = desktop.comment();
  QString url = desktop.url();
  QVariant exec = desktop.value("Exec");
  QVariant no_display = desktop.value("NoDisplay");
  if(!url.isEmpty())
    result["url"] = url;
  if(exec.isValid())
    result["exec"] = exec;
  if(no_display.isValid())
    result["no_display"] = no_display;

  return result;
}
示例#22
0
 void start()
 {
     m_xdg->startDetached();
 }
示例#23
0
void MimetypeViewer::currentMimetypeChanged()
{
    widget.iconLabel->hide();
    widget.descriptionLabel->setText(tr("None"));
    widget.mimetypeGroupBox->setEnabled(false);

    widget.patternsLabel->clear();
    widget.patternsGroupBox->setEnabled(false);

    widget.appIcon->hide();
    widget.applicationLabel->clear();
    widget.applicationsGroupBox->setEnabled(false);

    QTreeWidgetItem *sel = widget.mimetypeTreeWidget->currentItem();

    if (!sel || sel->type() == GroupType) {
        return;
    }

    MimeTypeData mimeData = sel->data(0, Qt::UserRole).value<MimeTypeData>();

    QMimeDatabase db;
    XdgMimeType mt = db.mimeTypeForName(mimeData.name());
    if (mt.name().isEmpty())
        return;

    m_CurrentMime = mt;

    widget.descriptionLabel->setText(mimeData.comment());

    QIcon icon = m_CurrentMime.icon();
    if (! icon.isNull())
    {
        widget.iconLabel->setPixmap(icon.pixmap(widget.iconLabel->size()));
        widget.iconLabel->show();
    }

    widget.mimetypeGroupBox->setEnabled(true);
    widget.patternsLabel->setText(mimeData.patterns());
    widget.patternsGroupBox->setEnabled(true);

    XdgDesktopFile* defaultApp = XdgDesktopFileCache::getDefaultApp(m_CurrentMime.name());
    if (defaultApp && defaultApp->isValid())
    {
        QString nonLocalizedName = defaultApp->value("Name").toString();
        QString localizedName = defaultApp->localizedValue("Name", nonLocalizedName).toString();
        QIcon appIcon = defaultApp->icon();
        widget.appIcon->setPixmap(appIcon.pixmap(widget.iconLabel->size()));
        widget.appIcon->show();
        widget.applicationLabel->setText(localizedName);
        widget.chooseApplicationsButton->setText(tr("&Change..."));
    }
    else
    {
        widget.applicationLabel->setText(tr("None"));
        widget.chooseApplicationsButton->setText(tr("&Choose..."));
    }

    widget.applicationsGroupBox->setEnabled(true);

}