LicensePropsPlugin::LicensePropsPlugin(KPropertiesDialog *_props, const QStringList &) : KPropertiesDialogPlugin(_props) { m_vBox = new KVBox(); m_widget = new QWidget( m_vBox ); QVBoxLayout * vbox = new QVBoxLayout( m_widget ); QWidget *main = new QWidget(m_widget); vbox->addWidget( main ); licenseChooser = new LicenseChooser(main); connect( licenseChooser, SIGNAL(licenseChanged()), this, SLOT(setDirty()) ); m_widget->show(); // In case the dialog was shown already. if ( properties->items().count() == 1 ) { KFileItem *item = properties->item(); if (item->url().isLocalFile()) { _props->addPage( m_vBox, i18n("&License") ); QByteArray ba = item->localPath().toUtf8(); char *license = ll_read(ba.data()); if (license) { licenseChooser->setLicenseURI(QString::fromUtf8(license)); } else { ll_uri_t uri = ll_get_default(); licenseChooser->setLicenseURI(QString::fromUtf8(uri),false); free(uri); } } } }
void StackFolder::activatedDragAndDrop(const KFileItem &item) { QMimeData *mime = new QMimeData; QList<QUrl> urls; urls.append(item.url()); mime->setUrls(urls); QDrag *drag = new QDrag(view()); drag->setMimeData(mime); QString local_path = item.localPath(); PreviewGenerator *gen = PreviewGenerator::createInstance(); Q_ASSERT(gen != 0); if (gen->hasPreviewPixmap(local_path)) { drag->setPixmap(gen->getPreviewPixmap(item.localPath()).scaled(KIconLoader::SizeMedium, KIconLoader::SizeMedium, Qt::KeepAspectRatio)); } else drag->setPixmap(item.pixmap(0)); drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::CopyAction); }
void LicensePropsPlugin::applyChanges() { KFileItem *item = properties->item(); QByteArray byteArray = licenseChooser->licenseURI().toUtf8(); //watch out: we can't do uriEdit->text().toUtf8().data() because the result is //only valid as long as the QByteArray is around char *license = byteArray.data(); if (license[0] == '\0') license = NULL; QByteArray pathData = item->localPath().toUtf8(); ll_write(pathData.data(),license); }
void DolphinView::updateURL() { KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) : static_cast<KFileView*>(m_detailsView); KFileItem* fileItem = fileView->currentFileItem(); if (fileItem == 0) { return; } if (fileItem->isDir()) { // Prefer the local path over the URL. This assures that the // volume space information is correct. Assuming that the URL is media:/sda1, // and the local path is /windows/C: For the URL the space info is related // to the root partition (and hence wrong) and for the local path the space // info is related to the windows partition (-> correct). const QString localPath(fileItem->localPath()); if (localPath.isEmpty()) { setURL(fileItem->url()); } else { setURL(KURL(localPath)); } } else if (fileItem->isFile()) { // allow to browse through ZIP and tar files KMimeType::Ptr mime = fileItem->mimeTypePtr(); if (mime->is("application/x-zip")) { KURL url = fileItem->url(); url.setProtocol("zip"); setURL(url); } else if (mime->is("application/x-tar") || mime->is("application/x-tarz") || mime->is("application/x-tbz") || mime->is("application/x-tgz") || mime->is("application/x-tzo")) { KURL url = fileItem->url(); url.setProtocol("tar"); setURL(url); } else { fileItem->run(); } } else { fileItem->run(); } }
static KFileMetaInfo cachedMetaInfo(const KFileItem& file) { QString dbName="metainfocache"; if (!QSqlDatabase::contains(dbName)) { QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE",dbName); db.setDatabaseName(KStandardDirs::locateLocal("appdata", dbName+".sqlite")); if (KDE_ISUNLIKELY( !db.open() )) return KFileMetaInfo(file.url()); initDataBase(db); } QSqlDatabase db=QSqlDatabase::database(dbName); if (!db.isOpen()) return KFileMetaInfo(file.url()); static const QString fields[]={ "translation.translated", "translation.untranslated", "translation.fuzzy", "translation.last_translator", "translation.source_date", "translation.translation_date", "translation.translated_reviewer", "translation.translated_approver", "translation.fuzzy_reviewer", "translation.fuzzy_approver" }; static const int nFields = sizeof(fields) / sizeof(fields[0]); QByteArray result; QSqlQuery queryCache(db); queryCache.prepare("SELECT * from metainfo where filepath=?"); queryCache.bindValue(0, qHash(file.localPath())); queryCache.exec(); if (queryCache.next() && file.time(KFileItem::ModificationTime).dateTime()==queryCache.value(2).toDateTime()) { result=queryCache.value(1).toByteArray(); QDataStream stream(&result,QIODevice::ReadOnly); //unfortunately direct KFileMetaInfo << operator doesn't work KFileMetaInfo info; QVector<QVariant> keys; stream>>keys; for(int i=0;i<keys.count();i++) info.item(fields[i]).setValue(keys.at(i)); return info; }
KUrl::List PopupView::selectedUrls() const { Q_ASSERT(m_model); KUrl::List urls; foreach (const QModelIndex &index, m_selectionModel->selectedIndexes()) { KFileItem item = m_model->itemForIndex(index); // Prefer the local URL if there is one, since we can't trash remote URL's const QString path = item.localPath(); if (!path.isEmpty()) { urls.append(path); } else { urls.append(item.url()); } } return urls; }
PopupView::PopupView(const QModelIndex &index, const QPoint &pos, const bool &showPreview, const QStringList &previewPlugins, const IconView *parentView) : QWidget(0, Qt::X11BypassWindowManagerHint), m_view(0), m_parentView(parentView), m_busyWidget(0), m_iconView(0), m_parentViewModel(0), m_dirModel(0), m_model(0), m_actionCollection(this), m_newMenu(0), m_itemActions(0), m_showingMenu(false), m_showPreview(showPreview), m_delayedClose(false), m_previewPlugins(previewPlugins) { setAttribute(Qt::WA_TranslucentBackground); #ifdef Q_WS_X11 if (KWindowSystem::compositingActive()) { setAttribute(Qt::WA_NoSystemBackground, false); } #endif #ifdef Q_WS_WIN setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool); #endif KWindowSystem::setState(effectiveWinId(), NET::SkipTaskbar | NET::SkipPager); setAcceptDrops(true); QPalette pal = palette(); pal.setColor(backgroundRole(), Qt::transparent); pal.setColor(QPalette::Text, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); setPalette(pal); m_parentViewModel = static_cast<const ProxyModel*>(index.model()); KFileItem item = m_parentViewModel->itemForIndex(index); if (item.isDesktopFile()) { KDesktopFile file(item.localPath()); m_url = file.readUrl(); } else { m_url = item.targetUrl(); } m_background = new Plasma::FrameSvg(this); m_background->setImagePath("dialogs/background"); int left = m_background->marginSize(Plasma::LeftMargin); int top = m_background->marginSize(Plasma::TopMargin); int right = m_background->marginSize(Plasma::RightMargin); int bottom = m_background->marginSize(Plasma::BottomMargin); setContentsMargins(left, top, right, bottom); resize(parentView->sizeForRowsColumns(2, 3) + QSize(left + right, top + bottom)); const QRect available = QApplication::desktop()->availableGeometry(pos); QPoint pt = pos; if (pt.x() + width() > available.right()) { pt.rx() -= width(); } if (pt.x() < available.left()) { pt.rx() = available.left(); } if (pt.y() + height() > available.bottom()) { pt.ry() -= height(); } if (pt.y() < available.top()) { pt.ry() = available.top(); } Plasma::WindowEffects::overrideShadow(winId(), true); move(pt); show(); QTimer::singleShot(10, this, SLOT(init())); s_lastOpenClose.restart(); }
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(); } }
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; }