void InformationPanel::requestDelayedItemInfo(const KFileItem& item)
{
    if (!isVisible() || (item.isNull() && m_fileItem.isNull())) {
        return;
    }

    if (QApplication::mouseButtons() & Qt::LeftButton) {
        // Ignore the request of an item information when a rubberband
        // selection is ongoing.
        return;
    }

    cancelRequest();

    if (item.isNull()) {
        // The cursor is above the viewport. If files are selected,
        // show information regarding the selection.
        if (m_selection.size() > 0) {
            m_fileItem = KFileItem();
            m_infoTimer->start();
        }
    } else if (item.url().isValid() && !isEqualToShownUrl(item.url())) {
        // The cursor is above an item that is not shown currently
        m_urlCandidate = item.url();
        m_fileItem = item;
        m_infoTimer->start();
    }
}
Example #2
0
void FoldersPanel::slotItemActivated(int index)
{
    const KFileItem item = m_model->fileItem(index);
    if (!item.isNull()) {
        emit folderActivated(item.url());
    }
}
Example #3
0
void FoldersPanel::slotItemMiddleClicked(int index)
{
    const KFileItem item = m_model->fileItem(index);
    if (!item.isNull()) {
        emit folderMiddleClicked(item.url());
    }
}
Example #4
0
void KoRecentDocumentsPane::selectionChanged(const QModelIndex& index)
{
    if (index.isValid()) {
        KoFileListItem* item = static_cast<KoFileListItem*>(model()->itemFromIndex(index));
        m_openButton->setEnabled(true);
        m_titleLabel->setText(item->data(Qt::DisplayRole).toString());
        m_previewLabel->setPixmap(item->data(Qt::UserRole).value<QPixmap>());
        KFileItem fileItem = item->fileItem();

        if (!fileItem.isNull()) {
            QString details = QString("<center>%1<br>").arg(fileItem.url().path());
            details += "<table border=\"0\">";
            details += i18nc("File modification date and time. %1 is date time",
                             "<tr><td><b>Modified:</b></td><td>%1</td></tr>",
                             QString(fileItem.timeString(KFileItem::ModificationTime)));
            details += i18nc("File access date and time. %1 is date time",
                             "<tr><td><b>Accessed:</b></td><td>%1</td></tr>",
                             QString(fileItem.timeString(KFileItem::AccessTime)));
            details += "</table></center>";
            m_detailsLabel->setHtml(details);
        } else {
            m_detailsLabel->clear();
        }
    } else {
        m_openButton->setEnabled(false);
        m_titleLabel->clear();
        m_previewLabel->setPixmap(QPixmap());
        m_detailsLabel->clear();
    }
}
void InformationPanel::showItemInfo()
{
    if (!isVisible()) {
        return;
    }

    cancelRequest();

    if (m_fileItem.isNull() && (m_selection.count() > 1)) {
        // The information for a selection of items should be shown
        m_content->showItems(m_selection);
    } else {
        // The information for exactly one item should be shown
        KFileItem item;
        if (!m_fileItem.isNull()) {
            item = m_fileItem;
        } else if (!m_selection.isEmpty()) {
            Q_ASSERT(m_selection.count() == 1);
            item = m_selection.first();
        }

        if (item.isNull()) {
            // No item is hovered and no selection has been done: provide
            // an item for the currently shown directory.
            m_folderStatJob = KIO::stat(url(), KIO::HideProgressInfo);
            connect(m_folderStatJob, SIGNAL(result(KJob*)),
                    this, SLOT(slotFolderStatFinished(KJob*)));
        } else {
Example #6
0
QModelIndex SortedDirModel::indexForItem(const KFileItem& item) const
{
    if (item.isNull()) {
        return QModelIndex();
    }

    QModelIndex sourceIndex = d->mSourceModel->indexForItem(item);
    return mapFromSource(sourceIndex);
}
Example #7
0
void KoRecentDocumentsPane::selectionChanged(const QModelIndex& index)
{
    if (index.isValid()) {
        KoFileListItem* item = static_cast<KoFileListItem*>(model()->itemFromIndex(index));
        const KFileItem fileItem = item->fileItem();

        m_openButton->setEnabled(true);
        m_titleLabel->setText(item->data(Qt::DisplayRole).toString());

        QPixmap preview = item->data(PreviewRole).value<QPixmap>();
        if (preview.isNull()) {
            // need to fetch preview
            const KFileItemList fileList = KFileItemList() << fileItem;
#if KDE_IS_VERSION(4,6,80)
            QStringList availablePlugins = KIO::PreviewJob::availablePlugins();
            KIO::PreviewJob *previewJob = KIO::filePreview(fileList, QSize(PreviewExtent, PreviewExtent), &availablePlugins);
#else
            KIO::PreviewJob *previewJob = KIO::filePreview(fileList, PreviewExtent, PreviewExtent, 0);
#endif

            d->m_previewJobs.append(previewJob);
            connect(previewJob, SIGNAL(result(KJob*)), SLOT(previewResult(KJob*)));
            connect(previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
                    SLOT(updatePreview(KFileItem,QPixmap)));

            // for now set preview to icon
            preview = item->icon().pixmap(PreviewExtent);
            if (preview.width() < PreviewExtent && preview.height() < PreviewExtent) {
                preview = preview.scaled(PreviewExtent, PreviewExtent, Qt::KeepAspectRatio, Qt::SmoothTransformation);
            }
        }
        m_previewLabel->setPixmap(preview);

        if (!fileItem.isNull()) {
            QString details = QString("<center>%1<br>").arg(fileItem.url().path()) +
                "<table border=\"0\">" +
                i18nc("File modification date and time. %1 is date time",
                      "<tr><td><b>Modified:</b></td><td>%1</td></tr>",
                      QString(fileItem.timeString(KFileItem::ModificationTime))) +
                i18nc("File access date and time. %1 is date time",
                      "<tr><td><b>Accessed:</b></td><td>%1</td></tr>",
                      QString(fileItem.timeString(KFileItem::AccessTime))) +
                "</table></center>";
            m_detailsLabel->setHtml(details);
        } else {
            m_detailsLabel->clear();
        }
    } else {
        m_openButton->setEnabled(false);
        m_titleLabel->clear();
        m_previewLabel->setPixmap(QPixmap());
        m_detailsLabel->clear();
    }
}
Example #8
0
void IconView::contextMenuEvent( QContextMenuEvent* event )
{
    QModelIndex index = indexAt( event->pos() );
    if ( !index.isValid() || m_selectionModel->selectedIndexes().isEmpty() ) {
        QMenu* menu = new QMenu;
        menu->addAction( m_actionCollection.action( "new_menu" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "undo" ) );
        menu->addAction( m_actionCollection.action( "paste" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "refresh" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "wallpaper" ) );
        if ( event->reason() == QContextMenuEvent::Keyboard )
            menu->exec( QPoint( 0, 0 ) );
        else
            menu->exec( event->pos() );
        delete menu;
        return;
    }

    KFileItemList items;
    foreach ( const QModelIndex &index, m_selectionModel->selectedIndexes() ) {
        KFileItem item = m_model->itemForIndex( m_proxyModel->mapToSource( index ) );
        if ( !item.isNull() )
            items.append( item );
    }

    QAction* pasteTo = m_actionCollection.action( "pasteto" );
    if ( pasteTo ) {
        pasteTo->setEnabled( m_actionCollection.action( "paste" )->isEnabled() );
        pasteTo->setText( m_actionCollection.action( "paste" )->text() );
    }

    QList<QAction*> editActions;
    editActions.append( m_actionCollection.action( "rename" ) );
    editActions.append( m_actionCollection.action( "trash" ) );
    KConfigGroup configGroup( KGlobal::config(), "KDE" );
    bool showDeleteCommand = configGroup.readEntry( "ShowDeleteCommand", false );
    if ( showDeleteCommand )
        editActions.append( m_actionCollection.action( "del" ) );
    KParts::BrowserExtension::ActionGroupMap actionGroups;
    actionGroups.insert( "editactions", editActions );
    KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::ShowProperties;
    flags |= KParts::BrowserExtension::ShowUrlOperations;
    KonqPopupMenu* contextMenu = new KonqPopupMenu( items, KUrl(QDir::homePath()), m_actionCollection, m_newMenu,
                                                    KonqPopupMenu::ShowNewWindow, flags,
                                                    QApplication::desktop(),
                                                    KBookmarkManager::userBookmarksManager(),
                                                    actionGroups );
    contextMenu->exec( event->pos() );
    delete contextMenu;
}
Example #9
0
bool KindProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
    if (d->mKindFilter == MimeTypeUtils::Kinds()) {
        return true;
    }
    QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
    KFileItem fileItem = index.data(KDirModel::FileItemRole).value<KFileItem>();
    if (fileItem.isNull()) {
        return false;
    }
    MimeTypeUtils::Kinds kind = MimeTypeUtils::fileItemKind(fileItem);
    return d->mKindFilter & kind;
}
void DolphinViewContainer::showItemInfo(const KFileItem& item)
{
    if (item.isNull()) {
        // Only clear the status bar if unimportant messages are shown.
        // This prevents that information- or error-messages get hidden
        // by moving the mouse above the viewport or when closing the
        // context menu.
        if (m_statusBar->type() == DolphinStatusBar::Default) {
            m_statusBar->clear();
        }
    } else {
        m_statusBar->setMessage(item.getStatusBarInfo(), DolphinStatusBar::Default);
    }
}
Example #11
0
void KoRecentDocumentsPane::openFile(const QModelIndex& index)
{
    if (!index.isValid()) return;

    KConfigGroup cfgGrp(componentData().config(), "TemplateChooserDialog");
    cfgGrp.writeEntry("LastReturnType", "File");

    KoFileListItem* item = static_cast<KoFileListItem*>(model()->itemFromIndex(index));
    KFileItem fileItem = item->fileItem();

    if (!fileItem.isNull()) {
        emit openUrl(fileItem.url());
    }
}
void VersionControlObserver::verifyDirectory()
{
    if (!m_model) {
        return;
    }

    const KFileItem rootItem = m_model->rootItem();
    if (rootItem.isNull() || !rootItem.url().isLocalFile()) {
        return;
    }

    if (m_plugin) {
        m_plugin->disconnect(this);
    }

    m_plugin = searchPlugin(rootItem.url());
    if (m_plugin) {
        KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
        if (pluginV2) {
            connect(pluginV2, SIGNAL(itemVersionsChanged()),
                    this, SLOT(silentDirectoryVerification()));
        } else {
            connect(m_plugin, SIGNAL(versionStatesChanged()),
                    this, SLOT(silentDirectoryVerification()));
        }
        connect(m_plugin, SIGNAL(infoMessage(QString)),
                this, SIGNAL(infoMessage(QString)));
        connect(m_plugin, SIGNAL(errorMessage(QString)),
                this, SIGNAL(errorMessage(QString)));
        connect(m_plugin, SIGNAL(operationCompletedMessage(QString)),
                this, SIGNAL(operationCompletedMessage(QString)));

        if (!m_versionedDirectory) {
            m_versionedDirectory = true;

            // The directory is versioned. Assume that the user will further browse through
            // versioned directories and decrease the verification timer.
            m_dirVerificationTimer->setInterval(100);
        }
        updateItemStates();
    } else if (m_versionedDirectory) {
        m_versionedDirectory = false;

        // The directory is not versioned. Reset the verification timer to a higher
        // value, so that browsing through non-versioned directories is not slown down
        // by an immediate verification.
        m_dirVerificationTimer->setInterval(500);
    }
}
void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
                                                const QAbstractProxyModel* proxyModel,
                                                const DolphinModel* dolphinModel,
                                                const QModelIndex& index)
{
    const QModelIndex dirIndex = proxyModel->mapToSource(index);
    const KFileItem item = dolphinModel->itemForIndex(dirIndex);
    if (!item.isNull()) {
        // symbolic links are displayed in an italic font
        if (item.isLink()) {
            option.font.setItalic(true);
        }

        const int width = nameColumnWidth(item.text(), option);
        option.rect.setWidth(width);
    }
}
void View::slotListingCompleted()
{
  int index = 0;
  const QList<LocationNavigator::Element> history = m_locationNavigator->history(index);
  if (!history.isEmpty()) {
    LocationNavigator::Element element = history[index];
    const KFileItem fileItem = element.currentItem();
    
    if (!fileItem.isNull()) {
      m_detailsView->setCurrentIndex(m_proxyModel->mapFromSource(m_dirModel->indexForItem(fileItem)));
      m_detailsView->horizontalScrollBar()->setValue(element.contentsX());
      m_detailsView->verticalScrollBar()->setValue(element.contentsY());
    }
  }
  
  disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(slotListingCompleted()));
  emit urlChanged(m_locationNavigator->url());
}
Example #15
0
void StackFolder::updateIconWidget()
{
    if (!m_placesModel) {
        m_placesModel = new KFilePlacesModel(this);

        const QModelIndex index = m_placesModel->closestItem(m_topUrl);
        const KUrl url = m_placesModel->url(index);

        KFileItem item = m_dirModel->itemForIndex(QModelIndex());

        if (!item.isNull() && item.iconName() != "inode-directory") {
            m_icon = KIcon(item.iconName(), 0, item.overlays());
        } 
        else if (m_topUrl.protocol() == "desktop") {
            m_icon = KIcon("user-desktop");
        } 
        else if (m_topUrl.protocol() == "trash") {
            m_icon = m_model->rowCount() > 0 ? KIcon("user-trash-full") : KIcon("user-trash");
        } 
        else if (index.isValid() && url.equals(m_topUrl, KUrl::CompareWithoutTrailingSlash)) {
            m_icon = m_placesModel->icon(index);
        }

        m_iconAnimation1 = new QPropertyAnimation(this, "popupIconSize");
        m_iconAnimation1->setDuration(600);
        m_iconAnimation2 = new QPropertyAnimation(this, "popupIconSize");
        m_iconAnimation1->setDuration(600);
        m_iconAnimationGroup = new QSequentialAnimationGroup;
        m_iconAnimationGroup->addAnimation(m_iconAnimation1);
        m_iconAnimationGroup->addAnimation(m_iconAnimation2);
        m_iconAnimationGroup->setLoopCount(4);
        connect(m_iconAnimationGroup, SIGNAL(finished()), this, SLOT(iconAnimationFinished()));

        setPopupIcon(m_icon);

        // Update the tooltip
        Plasma::ToolTipContent data;
        data.setMainText(i18n("Stack Folder"));
        data.setSubText(m_topUrl.fileName(KUrl::IgnoreTrailingSlash));
        data.setImage(m_icon);
        Plasma::ToolTipManager::self()->setContent(this, data);

    }
}
Example #16
0
void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
{
    if (index >= 0) {
        KFileItem destItem = m_model->fileItem(index);
        if (destItem.isNull()) {
            return;
        }

        QDropEvent dropEvent(event->pos().toPoint(),
                             event->possibleActions(),
                             event->mimeData(),
                             event->buttons(),
                             event->modifiers());

        KIO::DropJob *job = DragAndDropHelper::dropUrls(destItem.url(), &dropEvent, this);
        if (job) {
            connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); });
        }
    }
}
Example #17
0
File: paste.cpp Project: KDE/kio
KIOWIDGETS_EXPORT QString KIO::pasteActionText(const QMimeData *mimeData, bool *enable, const KFileItem &destItem)
{
    bool canPasteData = false;
    QList<QUrl> urls;

    // mimeData can be 0 according to https://bugs.kde.org/show_bug.cgi?id=335053
    if (mimeData) {
        canPasteData = KIO::canPasteMimeData(mimeData);
        urls = KUrlMimeData::urlsFromMimeData(mimeData);
    } else {
        qCWarning(KIO_WIDGETS) << "QApplication::clipboard()->mimeData() is 0!";
    }

    QString text;
    if (!urls.isEmpty() || canPasteData) {
        // disable the paste action if no writing is supported
        if (!destItem.isNull()) {
            if (destItem.url().isEmpty()) {
                *enable = false;
            } else {
                *enable = KFileItemListProperties(KFileItemList() << destItem).supportsWriting();
            }
        } else {
            *enable = false;
        }

        if (urls.count() == 1 && urls.first().isLocalFile()) {
            const bool isDir = QFileInfo(urls.first().toLocalFile()).isDir();
            text = isDir ? i18nc("@action:inmenu", "Paste One Folder") :
                           i18nc("@action:inmenu", "Paste One File");
        } else if (!urls.isEmpty()) {
            text = i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls.count());
        } else {
            text = i18nc("@action:inmenu", "Paste Clipboard Contents...");
        }
    } else {
        *enable = false;
        text = i18nc("@action:inmenu", "Paste");
    }
    return text;
}
QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) const
{
    QList<QAction*> actions;

    bool hasNullItems = false;
    foreach (const KFileItem& item, items) {
        if (item.isNull()) {
            kWarning() << "Requesting version-control-actions for empty items";
            hasNullItems = true;
            break;
        }
    }

    if (!m_model || hasNullItems) {
        return actions;
    }

    KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin);
    if (pluginV2) {
        // Use version 2 of the KVersionControlPlugin which allows providing actions
        // also for non-versioned directories.
        actions = pluginV2->actions(items);
    } else if (isVersioned()) {
        // Support deprecated interfaces from KVersionControlPlugin version 1.
        // Context menu actions where only available for versioned directories.
        QString directory;
        if (items.count() == 1) {
            const KFileItem rootItem = m_model->rootItem();
            if (!rootItem.isNull() && items.first().url() == rootItem.url()) {
                directory = rootItem.url().path(KUrl::AddTrailingSlash);
            }
        }

        actions = directory.isEmpty() ? m_plugin->contextMenuActions(items)
                                      : m_plugin->contextMenuActions(directory);
    }

    return actions;
}
Example #19
0
void PopupView::showContextMenu(QWidget *widget, const QPoint &screenPos, const QList<QModelIndex> &indexes)
{
    Q_UNUSED(widget)
    // contextMenuRequest is only called from the icon view, which is created in init()
    // which mean m_model should always be initialized
    Q_ASSERT(m_model);

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

    if (m_actionCollection.isEmpty()) {
        createActions();
    }

    KFileItemList items;
    bool hasRemoteFiles = false;
    bool isTrashLink = false;

    foreach (const QModelIndex &index, m_selectionModel->selectedIndexes()) {
        KFileItem item = m_model->itemForIndex(index);
        if (!item.isNull()) {
            hasRemoteFiles |= item.localPath().isEmpty();
            items.append(item);
        }
    }

    // Check if we're showing the menu for the trash link
    if (items.count() == 1 && items.at(0).isDesktopFile()) {
        KDesktopFile file(items.at(0).localPath());
        if (file.readType() == "Link" && file.readUrl() == "trash:/") {
            isTrashLink = true;
        }
    }

    QAction *pasteTo = m_actionCollection.action("pasteto");
    if (pasteTo) {
        if (QAction *paste = m_actionCollection.action("paste")) {
            pasteTo->setEnabled(paste->isEnabled());
            pasteTo->setText(paste->text());
        }
    }

    QList<QAction*> editActions;
    editActions.append(m_actionCollection.action("rename"));

    KConfigGroup configGroup(KGlobal::config(), "KDE");
    bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);

    // Don't add the "Move to Trash" action if we're showing the menu for the trash link
    if (!isTrashLink) {
        if (!hasRemoteFiles) {
            editActions.append(m_actionCollection.action("trash"));
        } else {
            showDeleteCommand = true;
        }
    }
    if (showDeleteCommand) {
        editActions.append(m_actionCollection.action("del"));
    }

    KParts::BrowserExtension::ActionGroupMap actionGroups;
    actionGroups.insert("editactions", editActions);

    KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::ShowProperties;
    flags |= KParts::BrowserExtension::ShowUrlOperations;

    // m_newMenu can be NULL here but KonqPopupMenu does handle this.
    KonqPopupMenu *contextMenu = new KonqPopupMenu(items, m_url, m_actionCollection, m_newMenu,
                                                   KonqPopupMenu::ShowNewWindow, flags,
                                                   QApplication::desktop(),
                                                   KBookmarkManager::userBookmarksManager(),
                                                   actionGroups);

    connect(contextMenu->fileItemActions(), SIGNAL(openWithDialogAboutToBeShown()), this, SLOT(openWithDialogAboutToShow()));

    m_showingMenu = true;
    contextMenu->exec(screenPos);
    delete contextMenu;
    m_showingMenu = false;

    if (pasteTo) {
        pasteTo->setEnabled(false);
    }

    if (m_delayedClose) {
        m_delayedClose = false;
        closeThisAndParentPopup();
    }
}
Example #20
0
QUrl SortedDirModel::urlForIndex(const QModelIndex& index) const
{
    KFileItem item = itemForIndex(index);
    return item.isNull() ? QUrl() : item.url();
}