Example #1
0
void MediaNotifier::notify(KFileItem &medium)
{
    kdDebug() << "Notification triggered." << endl;

    NotifierSettings *settings = new NotifierSettings();

    if(settings->autoActionForMimetype(medium.mimetype()) == 0L)
    {
        QValueList< NotifierAction * > actions = settings->actionsForMimetype(medium.mimetype());

        // If only one action remains, it's the "do nothing" action
        // no need to popup in this case.
        if(actions.size() > 1)
        {
            NotificationDialog *dialog = new NotificationDialog(medium, settings);
            dialog->show();
        }
    }
    else
    {
        NotifierAction *action = settings->autoActionForMimetype(medium.mimetype());
        action->execute(medium);
        delete settings;
    }
}
Example #2
0
QVariant DirModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) {
        return QVariant();
    }

    switch (role) {
    case UrlRole: {
        KFileItem item = itemForIndex(index);
        return item.url().toString();
    }
    case MimeTypeRole: {
        KFileItem item = itemForIndex(index);
        return item.mimetype();
    }
    case Thumbnail: {
        KFileItem item = itemForIndex(index);
        QImage preview = QImage(m_screenshotSize, QImage::Format_ARGB32_Premultiplied);

        if (m_imageCache->findImage(item.url().toString(), &preview)) {
            return preview;
        }

        m_previewTimer->start(100);
        const_cast<DirModel *>(this)->m_filesToPreview[item.url()] = QPersistentModelIndex(index);
    }
    default:
        return KDirModel::data(index, role);
    }
}
bool KFileItemModelFilter::matchesType(const KFileItem& item) const
{
    foreach (const QString& mimeType, m_mimeTypes) {
        if (item.mimetype() == mimeType) {
            return true;
        }
    }

    return m_mimeTypes.isEmpty();
}
Example #4
0
QVariantMap DirModel::get(int i) const
{
    QModelIndex modelIndex = index(i, 0);

    KFileItem item = itemForIndex(modelIndex);
    QString url = item.url().toString();
    QString mimeType = item.mimetype();

    QVariantMap ret;
    ret.insert(QStringLiteral("url"), QVariant(url));
    ret.insert(QStringLiteral("mimeType"), QVariant(mimeType));

    return ret;
}
void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
{
    KUrl url = item.targetUrl();

    if (item.isDir()) {
        m_view->setUrl(url);
        return;
    }

    const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
    const bool browseThroughArchives = settings->browseThroughArchives();
    if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
        // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
        // zip:/<path>/ when clicking on a zip file, etc.
        // The .protocol file specifies the mimetype that the kioslave handles.
        // Note that we don't use mimetype inheritance since we don't want to
        // open OpenDocument files as zip folders...
        const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
        if (!protocol.isEmpty()) {
            url.setProtocol(protocol);
            m_view->setUrl(url);
            return;
        }
    }

    if (item.mimetype() == "application/x-desktop") {
        // redirect to the url in Type=Link desktop files
        KDesktopFile desktopFile(url.toLocalFile());
        if (desktopFile.hasLinkType()) {
            url = desktopFile.readUrl();
            m_view->setUrl(url);
            return;
        }
    }

    item.run();
}
Example #6
0
QVariantList createListForFileItem(const KFileItem &fileItem)
{
    QVariantList list;
    if (fileItem.url() == KUrl("trash:/")) {
        list << createEmptyTrashItem() << createSeparatorActionItem();
    }
    KService::List services = KMimeTypeTrader::self()->query(fileItem.mimetype(), "Application");
    if (!services.isEmpty()) {
        list << createTitleActionItem(i18n("Open with:"));
        Q_FOREACH(const KService::Ptr service, services) {
            const QString text = service->name().replace('&', "&&");
            QVariantMap item = createActionItem(text, "_homerun_fileItem_openWith", service->entryPath());
            QString iconName = service->icon();
            if (!iconName.isEmpty()) {
                item["icon"] = KIcon(service->icon());
            }
            list << item;
        }
        list << createSeparatorActionItem();
    }
int DolphinContextMenu::insertOpenWithItems(KPopupMenu* popup,
                                            QValueVector<KService::Ptr>& openWithVector)
{
    // Prepare 'Open With' sub menu. Usually a sub menu is created, where all applications
    // are listed which are registered to open the item. As last entry "Other..." will be
    // attached which allows to select a custom application. If no applications are registered
    // no sub menu is created at all, only "Open With..." will be offered.
    const KFileItemList* list = m_dolphinView->selectedItems();
    assert(list != 0);

    bool insertOpenWithItems = true;
    const QString contextMimeType(m_fileInfo->mimetype());
    KFileItemListIterator mimeIt(*list);
    KFileItem* item = 0;
    while (insertOpenWithItems && ((item = mimeIt.current()) != 0)) {
        insertOpenWithItems = (contextMimeType == item->mimetype());
        ++mimeIt;
    }

    int openWithID = -1;

    if (insertOpenWithItems) {
        // fill the 'Open with' sub menu with application types
        const KMimeType::Ptr mimePtr = KMimeType::findByURL(m_fileInfo->url());
        KTrader::OfferList offers = KTrader::self()->query(mimePtr->name(),
                                                           "Type == 'Application'");
        int index = openWithIDStart;
        if (offers.count() > 0) {
            KTrader::OfferList::Iterator it;
            KPopupMenu* openWithMenu = new KPopupMenu();
            for(it = offers.begin(); it != offers.end(); ++it) {
                // The offer list from the KTrader returns duplicate
                // application entries. Although this seems to be a configuration
                // problem outside the scope of Dolphin, duplicated entries just
                // will be skipped here.
                const QString appName((*it)->name());
                if (!containsEntry(openWithMenu, appName)) {
                    openWithMenu->insertItem((*it)->pixmap(KIcon::Small),
                                            appName, index);
                    openWithVector.append(*it);
                    ++index;
                }
            }

            openWithMenu->insertSeparator();
            openWithMenu->insertItem(i18n("&Other..."), index);
            popup->insertItem(i18n("Open With"), openWithMenu);
        }
        else {
            // No applications are registered, hence just offer
            // a "Open With..." item instead of a sub menu containing
            // only one entry.
            popup->insertItem(i18n("Open With..."), openWithIDStart);
        }
        openWithID = index;
    }
    else {
        // At least one of the selected items has a different MIME type. In this case
        // just show a disabled "Open With..." entry.
        popup->insertItem(i18n("Open With..."), openWithIDStart);
        popup->setItemEnabled(openWithIDStart, false);
    }

    popup->setItemEnabled(openWithID, insertOpenWithItems);

    return openWithID;
}
Example #8
0
bool MediaNotifier::autostart(const KFileItem &medium)
{
    QString mimetype = medium.mimetype();

    bool is_cdrom = mimetype.startsWith("cd") || mimetype.startsWith("dvd");
    bool is_mounted = mimetype.endsWith("_mounted");

    // We autorun only on CD/DVD or removable disks (USB, Firewire)
    if(!(is_cdrom || is_mounted) && mimetype != "media/removable_mounted")
    {
        return false;
    }


    // Here starts the 'Autostart Of Applications After Mount' implementation

    // The desktop environment MAY ignore Autostart files altogether
    // based on policy set by the user, system administrator or vendor.
    MediaManagerSettings::self()->readConfig();
    if(!MediaManagerSettings::self()->autostartEnabled())
    {
        return false;
    }

    // From now we're sure the medium is already mounted.
    // We can use the local path for stating, no need to use KIO here.
    bool local;
    QString path = medium.mostLocalURL(local).path(); // local is always true here...

    // When a new medium is mounted the root directory of the medium should
    // be checked for the following Autostart files in order of precedence:
    // .autorun, autorun, autorun.sh
    QStringList autorun_list;
    autorun_list << ".autorun"
                 << "autorun"
                 << "autorun.sh";

    QStringList::iterator it = autorun_list.begin();
    QStringList::iterator end = autorun_list.end();

    for(; it != end; ++it)
    {
        if(QFile::exists(path + "/" + *it))
        {
            return execAutorun(medium, path, *it);
        }
    }

    // When a new medium is mounted the root directory of the medium should
    // be checked for the following Autoopen files in order of precedence:
    // .autoopen, autoopen
    QStringList autoopen_list;
    autoopen_list << ".autoopen"
                  << "autoopen";

    it = autoopen_list.begin();
    end = autoopen_list.end();

    for(; it != end; ++it)
    {
        if(QFile::exists(path + "/" + *it))
        {
            return execAutoopen(medium, path, *it);
        }
    }

    return false;
}
Example #9
0
void ServiceLoader::loadServices(const KFileItem item, DOM::DOMString &html, int &count)
{
  popups.clear();
  
  KURL url = item.url();
  QString mimeType = item.mimetype();
  QString mimeGroup = mimeType.left(mimeType.find('/'));
  
  urlList.clear();
  urlList.append(url);
  
  QStringList dirs = KGlobal::dirs()->findDirs( "data", "konqueror/servicemenus/" );
  KConfig config("metabarrc", true, false);
  config.setGroup("General");
  int maxActions = config.readNumEntry("MaxActions");
  bool matchAll = false; // config.readBoolEntry("MatchAll");
  
  int id = 0;
  QString idString;
  
  for(QStringList::Iterator dit = dirs.begin(); dit != dirs.end(); ++dit){
    idString.setNum(id);
  
    QDir dir(*dit);
    QStringList entries = dir.entryList("*.desktop", QDir::Files);
    
    for(QStringList::Iterator eit = entries.begin(); eit != entries.end(); ++eit){
      KSimpleConfig cfg( *dit + *eit, true );
      cfg.setDesktopGroup();
      
      if(cfg.hasKey("X-KDE-ShowIfRunning" )){
        const QString app = cfg.readEntry( "X-KDE-ShowIfRunning" );
        if(!kapp->dcopClient()->isApplicationRegistered(app.utf8())){
          continue;
        }
      }

      if(cfg.hasKey("X-KDE-Protocol")){
        const QString protocol = cfg.readEntry( "X-KDE-Protocol" );
        if(protocol != url.protocol()){
          continue;
        }
      }
      
      else if(url.protocol() == "trash"){
        continue;
      }

      if(cfg.hasKey("X-KDE-Require")){
        const QStringList capabilities = cfg.readListEntry( "X-KDE-Require" );
        if (capabilities.contains( "Write" )){
          continue;
        }
      }

      if ( cfg.hasKey( "Actions" ) && cfg.hasKey( "ServiceTypes" ) ){
          const QStringList types = cfg.readListEntry( "ServiceTypes" );
          const QStringList excludeTypes = cfg.readListEntry( "ExcludeServiceTypes" );
          bool ok = false;

          for (QStringList::ConstIterator it = types.begin(); it != types.end() && !ok; ++it){
            bool checkTheMimetypes = false;
          
            if(matchAll){
            // first check if we have an all mimetype
              if (*it == "all/all" || *it == "allfiles"){
                checkTheMimetypes = true;
              }
  
              // next, do we match all files?
              if (!ok && !item.isDir() && *it == "all/allfiles"){
                checkTheMimetypes = true;
              }
            }

            // if we have a mimetype, see if we have an exact or a type globbed match
            if(!ok && (!mimeType.isEmpty() && *it == mimeType) ||
              (!mimeGroup.isEmpty() && ((*it).right(1) == "*" && (*it).left((*it).find('/')) == mimeGroup)))
            {
              checkTheMimetypes = true;
            }

            if(checkTheMimetypes){
              ok = true;
              
              for(QStringList::ConstIterator itex = excludeTypes.begin(); itex != excludeTypes.end(); ++itex){
                if( ((*itex).right(1) == "*" && (*itex).left((*itex).find('/')) == mimeGroup) ||
                    ((*itex) == mimeType))
                {
                  ok = false;
                  break;
                }
              }
            }
          }
        if (ok){
          const QString priority = cfg.readEntry("X-KDE-Priority");
          const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
          bool usePopup = false;
          KPopupMenu *popup;
          
          if(!submenuName.isEmpty()){
            usePopup = true;
            
            if(popups[submenuName]){
              popup = popups[submenuName];
            }
            else{              
              MetabarWidget::addEntry(html, submenuName, "servicepopup://" + idString, "1rightarrow", "popup" + idString, count < maxActions ? QString::null : QString("hiddenaction"), count >= maxActions);
              
              popup = new KPopupMenu();
              popups.insert(idString, popup);
              
              count++;
            }
          }
          
          QValueList<KDEDesktopMimeType::Service> list = KDEDesktopMimeType::userDefinedServices( *dit + *eit, url.isLocalFile());
          
          for (QValueList<KDEDesktopMimeType::Service>::iterator it = list.begin(); it != list.end(); ++it){
          
            if(usePopup){
              KAction *action = new KAction((*it).m_strName, (*it).m_strIcon, KShortcut(), this, SLOT(runAction()), popup, idString.utf8());
              action->plug(popup);
            }
            else{
              MetabarWidget::addEntry(html, (*it).m_strName, "service://" + idString, (*it).m_strIcon, QString::null, count < maxActions ? QString::null : QString("hiddenaction"), count >= maxActions);
              count++;
            }
            
            services.insert(idString, *it);
            id++;
            idString.setNum(id);
          }
        }
      }
    }
  }
}
void InformationPanelContent::showItem(const KFileItem& item)
{
    // If there is a preview job, kill it to prevent that we have jobs for
    // multiple items running, and thus a race condition (bug 250787).
    if (m_previewJob) {
        m_previewJob->kill();
    }

    const QUrl itemUrl = item.url();
    const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && item.localPath().isEmpty();
    if (!applyPlace(itemUrl)) {
        setNameLabelText(item.text());
        if (isSearchUrl) {
            // in the case of a search-URL the URL is not readable for humans
            // (at least not useful to show in the Information Panel)
            KIconLoader iconLoader;
            QPixmap icon = iconLoader.loadIcon(QStringLiteral("nepomuk"),
                                               KIconLoader::NoGroup,
                                               KIconLoader::SizeEnormous);
            m_preview->setPixmap(icon);
        } else {
            // try to get a preview pixmap from the item...

            // Mark the currently shown preview as outdated. This is done
            // with a small delay to prevent a flickering when the next preview
            // can be shown within a short timeframe. This timer is not started
            // for directories, as directory previews might fail and return the
            // same icon.
            if (!item.isDir()) {
                m_outdatedPreviewTimer->start();
            }

            m_previewJob = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
            m_previewJob->setScaleType(KIO::PreviewJob::Unscaled);
            m_previewJob->setIgnoreMaximumSize(item.isLocalFile());
            if (m_previewJob->ui()) {
                KJobWidgets::setWindow(m_previewJob, this);
            }

            connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview,
                    this, &InformationPanelContent::showPreview);
            connect(m_previewJob.data(), &KIO::PreviewJob::failed,
                    this, &InformationPanelContent::showIcon);
        }
    }

    if (m_metaDataWidget) {
        m_metaDataWidget->show();
        m_metaDataWidget->setItems(KFileItemList() << item);
    }

    if (InformationPanelSettings::previewsShown()) {
        const QString mimeType = item.mimetype();
        const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/"));
        if (usePhonon) {
            m_phononWidget->show();
            m_phononWidget->setUrl(item.targetUrl());
            if (m_preview->isVisible()) {
                m_phononWidget->setVideoSize(m_preview->size());
            }
        } else {
            m_phononWidget->hide();
            m_preview->setVisible(true);
        }
    } else {
        m_phononWidget->hide();
    }

    m_item = item;
}
void InformationPanelContent::showItem(const KFileItem& item)
{
    m_pendingPreview = false;

    const KUrl itemUrl = item.url();
    const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty();
    if (!applyPlace(itemUrl)) {
        setNameLabelText(item.text());
        if (isSearchUrl) {
            // in the case of a search-URL the URL is not readable for humans
            // (at least not useful to show in the Information Panel)
            KIconLoader iconLoader;
            QPixmap icon = iconLoader.loadIcon("nepomuk",
                                               KIconLoader::NoGroup,
                                               KIconLoader::SizeEnormous);
            m_preview->setPixmap(icon);
        } else {
            // try to get a preview pixmap from the item...
            m_pendingPreview = true;

            // Mark the currently shown preview as outdated. This is done
            // with a small delay to prevent a flickering when the next preview
            // can be shown within a short timeframe. This timer is not started
            // for directories, as directory previews might fail and return the
            // same icon.
            if (!item.isDir()) {
                m_outdatedPreviewTimer->start();
            }

            KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
            job->setScaleType(KIO::PreviewJob::Unscaled);
            job->setIgnoreMaximumSize(item.isLocalFile());
            if (job->ui()) {
                job->ui()->setWindow(this);
            }

            connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
                    this, SLOT(showPreview(KFileItem,QPixmap)));
            connect(job, SIGNAL(failed(KFileItem)),
                    this, SLOT(showIcon(KFileItem)));
        }
    }

    if (m_metaDataWidget) {
        m_metaDataWidget->show();
        m_metaDataWidget->setItems(KFileItemList() << item);
    }

    if (InformationPanelSettings::previewsShown()) {
        const QString mimeType = item.mimetype();
        const bool usePhonon = mimeType.startsWith("audio/") || mimeType.startsWith("video/");
        if (usePhonon) {
            m_phononWidget->show();
            m_phononWidget->setUrl(item.targetUrl());
            if (m_preview->isVisible()) {
                m_phononWidget->setVideoSize(m_preview->size());
            }
        } else {
            m_phononWidget->hide();
            m_preview->setVisible(true);
        }
    } else {
        m_phononWidget->hide();
    }

    m_item = item;
}