X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4b0293e22ea169b0f8493644f2c4e8ef80e4e8fe..397b9bd4502a5aeab7da54dfcce0e4faa4a59ee4:/src/infosidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index 645300ae6..61a7b0643 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -26,16 +26,12 @@ #include #include -#include #include #include #include -#include -#include -//Added by qt3to4: #include #include -#include +#include #include #include @@ -46,10 +42,13 @@ #include #include #include +#include #include "dolphinmainwindow.h" +#include "dolphinapplication.h" #include "pixmapviewer.h" #include "dolphinsettings.h" +#include "metadataloader.h" InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : SidebarPage(mainWindow, parent), @@ -58,9 +57,8 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) m_timer(0), m_preview(0), m_name(0), - m_currInfoLineIdx(0), - m_infoGrid(0), - m_actionBox(0) + m_infos(0), + m_metadata(DolphinApplication::app()->metadataLoader()) { const int spacing = KDialog::spacingHint(); @@ -68,7 +66,7 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); - Q3VBoxLayout* layout = new Q3VBoxLayout(this); + QVBoxLayout* layout = new QVBoxLayout; layout->setSpacing(spacing); // preview @@ -84,15 +82,27 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) m_name->setMinimumHeight(fontMetrics.height() * 3); m_name->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); - QWidget* sep1 = new Q3HGroupBox(this); // TODO: check whether default widget exist for this? - sep1->setFixedHeight(1); + KSeparator* sep1 = new KSeparator(this); // general information - m_infoGrid = new Q3Grid(2, this); - m_infoGrid->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - - QWidget* sep2 = new Q3HGroupBox(this); // TODO: check whether default widget exist for this? - sep2->setFixedHeight(1); + m_infos = new QLabel(this); + m_infos->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + m_infos->setTextFormat(Qt::RichText); + + KSeparator* sep2 = new KSeparator(this); + + // annotation + KSeparator* sep3 = 0; + if (m_metadata->storageUp()) { + m_annotationLabel = new QLabel(this); + m_annotationLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_annotationLabel->setTextFormat(Qt::RichText); + m_annotationLabel->setWordWrap(true); + m_annotationButton = new QPushButton("", this); + m_annotationButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + connect(m_annotationButton, SIGNAL(released()), this, SLOT(changeAnnotation())); + sep3 = new KSeparator(this); + } // actions m_actionBox = new KVBox(this); @@ -106,11 +116,16 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) layout->addWidget(m_preview); layout->addWidget(m_name); layout->addWidget(sep1); - layout->addWidget(m_infoGrid); + layout->addWidget(m_infos); layout->addWidget(sep2); + if (m_metadata->storageUp()) { + layout->addWidget(m_annotationLabel); + layout->addWidget(m_annotationButton); + layout->addWidget(sep3); + } layout->addWidget(m_actionBox); layout->addWidget(dummy); - + setLayout(layout); connect(mainWindow, SIGNAL(selectionChanged()), this, SLOT(showItemInfo())); @@ -156,10 +171,14 @@ void InfoSidebarPage::showItemInfo() // show the preview... DolphinView* view = mainWindow()->activeView(); const KFileItemList selectedItems = view->selectedItems(); + KUrl file; if (selectedItems.count() > 1) { m_multipleSelection = true; + } else if(selectedItems.count() == 0) { + file = m_shownUrl; + } else { + file = selectedItems[0]->url(); } - if (m_multipleSelection) { KIconLoader iconLoader; QPixmap icon = iconLoader.loadIcon("exec", @@ -168,24 +187,30 @@ void InfoSidebarPage::showItemInfo() m_preview->setPixmap(icon); m_name->setText(i18n("%1 items selected",selectedItems.count())); } - else if (!applyBookmark()) { + else if (!applyBookmark(file)) { // try to get a preview pixmap from the item... KUrl::List list; - list.append(m_shownUrl); + list.append(file); m_pendingPreview = true; m_preview->setPixmap(QPixmap()); KIO::PreviewJob* job = KIO::filePreview(list, m_preview->width(), - K3Icon::SizeEnormous); + K3Icon::SizeEnormous, + 0, + 0, + true, + false); + job->setIgnoreMaximumSize(true); + connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)), this, SLOT(gotPreview(const KFileItem*, const QPixmap&))); connect(job, SIGNAL(failed(const KFileItem*)), this, SLOT(slotPreviewFailed(const KFileItem*))); QString text(""); - text.append(m_shownUrl.fileName()); + text.append(file.fileName()); text.append(""); m_name->setText(text); } @@ -203,7 +228,7 @@ void InfoSidebarPage::slotTimeout() void InfoSidebarPage::slotPreviewFailed(const KFileItem* item) { m_pendingPreview = false; - if (!applyBookmark()) { + if (!applyBookmark(item->url())) { m_preview->setPixmap(item->pixmap(K3Icon::SizeEnormous)); } } @@ -243,12 +268,12 @@ void InfoSidebarPage::connectToActiveView() showItemInfo(); } -bool InfoSidebarPage::applyBookmark() +bool InfoSidebarPage::applyBookmark(const KUrl& url) { KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); KBookmark bookmark = root.first(); while (!bookmark.isNull()) { - if (m_shownUrl.equals(bookmark.url(), KUrl::CompareWithoutTrailingSlash)) { + if (url.equals(bookmark.url(), KUrl::CompareWithoutTrailingSlash)) { QString text(""); text.append(bookmark.text()); text.append(""); @@ -275,10 +300,6 @@ void InfoSidebarPage::cancelRequest() void InfoSidebarPage::createMetaInfo() { - // To prevent a flickering it's important to reuse available - // labels instead of deleting them and recreate them afterwards. - // The methods beginInfoLines(), addInfoLine() and endInfoLines() - // take care of this. beginInfoLines(); DolphinView* view = mainWindow()->activeView(); if (!view->hasSelection()) { @@ -288,56 +309,47 @@ void InfoSidebarPage::createMetaInfo() if (fileItem.isDir()) { addInfoLine(i18n("Type:"), i18n("Directory")); } - else { - addInfoLine(i18n("Type:"), fileItem.mimeComment()); - - QString sizeText(KIO::convertSize(fileItem.size())); - addInfoLine(i18n("Size:"), sizeText); - addInfoLine(i18n("Modified:"), fileItem.timeString()); - - const KFileMetaInfo& metaInfo = fileItem.metaInfo(); - if (metaInfo.isValid()) { - QStringList keys = metaInfo.supportedKeys(); - for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { - if (showMetaInfo(*it)) { - KFileMetaInfoItem metaInfoItem = metaInfo.item(*it); - addInfoLine(*it, metaInfoItem.string()); - } + showAnnotation(m_shownUrl); + } + else if (view->selectedItems().count() == 1) { + KFileItem* fileItem = view->selectedItems()[0]; + addInfoLine(i18n("Type:"), fileItem->mimeComment()); + + QString sizeText(KIO::convertSize(fileItem->size())); + addInfoLine(i18n("Size:"), sizeText); + addInfoLine(i18n("Modified:"), fileItem->timeString()); + + const KFileMetaInfo& metaInfo = fileItem->metaInfo(); + if (metaInfo.isValid()) { + QStringList keys = metaInfo.supportedKeys(); + for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { + if (showMetaInfo(*it)) { + KFileMetaInfoItem metaInfoItem = metaInfo.item(*it); + addInfoLine(*it, metaInfoItem.value().toString()); } } } + showAnnotation(fileItem->url()); + } + else { + showAnnotations(view->selectedItems().urlList()); + unsigned long int totSize = 0; + foreach(KFileItem* item, view->selectedItems()) { + totSize += item->size(); //FIXME what to do with directories ? (same with the one-item-selected-code), item->size() does not return the size of the content : not very instinctive for users + } + addInfoLine(i18n("Total size:"), KIO::convertSize(totSize)); } endInfoLines(); } void InfoSidebarPage::beginInfoLines() { - m_currInfoLineIdx = 0; + m_infoLines = QString(""); } void InfoSidebarPage::endInfoLines() { - if (m_currInfoLineIdx <= 0) { - return; - } - - // remove labels which have not been used - if (m_currInfoLineIdx < static_cast(m_infoWidgets.count())) { - Q3PtrListIterator deleteIter(m_infoWidgets); - deleteIter += m_currInfoLineIdx; - - QWidget* widget = 0; - int removeCount = 0; - while ((widget = deleteIter.current()) != 0) { - widget->close(); - widget->deleteLater(); - ++deleteIter; - ++removeCount; - } - for (int i = 0; i < removeCount; ++i) { - m_infoWidgets.removeLast(); - } - } + m_infos->setText(m_infoLines); } bool InfoSidebarPage::showMetaInfo(const QString& key) const @@ -380,33 +392,9 @@ bool InfoSidebarPage::showMetaInfo(const QString& key) const void InfoSidebarPage::addInfoLine(const QString& labelText, const QString& infoText) { - QString labelStr(""); - labelStr.append(labelText); - labelStr.append(" "); - - const int count = m_infoWidgets.count(); - if (m_currInfoLineIdx < count - 1) { - // reuse available labels - m_infoWidgets.at(m_currInfoLineIdx++)->setText(labelStr); - m_infoWidgets.at(m_currInfoLineIdx++)->setText(infoText); - } - else { - // no labels are available anymore, hence create 2 new ones - QLabel* label = new QLabel(labelStr, m_infoGrid); - label->setTextFormat(Qt::RichText); - label->setAlignment(Qt::AlignRight | - Qt::AlignTop); - label->show(); - m_infoWidgets.append(label); - - QLabel* info = new QLabel(infoText, m_infoGrid); - info->setTextFormat(Qt::RichText); - info->setAlignment(Qt::AlignTop | Qt::TextWordWrap); - info->show(); - m_infoWidgets.append(info); - - m_currInfoLineIdx += 2; - } + if (!m_infoLines.isEmpty()) + m_infoLines += "
"; + m_infoLines += QString("%1 %2").arg(labelText).arg(infoText); } void InfoSidebarPage::insertActions() @@ -442,13 +430,12 @@ void InfoSidebarPage::insertActions() QStringList dirs = KGlobal::dirs()->findDirs("data", "dolphin/servicemenus/"); for (QStringList::ConstIterator dirIt = dirs.begin(); dirIt != dirs.end(); ++dirIt) { QDir dir(*dirIt); - QStringList entries = dir.entryList("*.desktop", QDir::Files); + QStringList entries = dir.entryList(QStringList("*.desktop"), QDir::Files); for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) { - KSimpleConfig cfg(*dirIt + *entryIt, true); - cfg.setDesktopGroup(); + KConfigGroup cfg(KSharedConfig::openConfig( *dirIt + *entryIt, KConfig::OnlyLocal ), "Desktop Entry" ); if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) { - const QStringList types = cfg.readListEntry("ServiceTypes"); + const QStringList types = cfg.readEntry("ServiceTypes", QStringList(), ','); for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) { // check whether the mime type is equal or whether the // mimegroup (e. g. image/*) is supported @@ -493,7 +480,7 @@ void InfoSidebarPage::insertActions() QPushButton* button = new QPushButton(submenuName, m_actionBox); button->setFlat(true); - button->setPopup(popup); + button->setMenu(popup); button->show(); m_actionWidgets.append(button); } @@ -506,7 +493,7 @@ void InfoSidebarPage::insertActions() for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) { KDEDesktopMimeType::Service service = (*serviceIt); if (popup == 0) { - ServiceButton* button = new ServiceButton(SmallIcon(service.m_strIcon), + ServiceButton* button = new ServiceButton(KIcon(service.m_strIcon), service.m_strName, m_actionBox, actionsIndex); @@ -516,7 +503,7 @@ void InfoSidebarPage::insertActions() button->show(); } else { - popup->insertItem(SmallIcon(service.m_strIcon), service.m_strName, actionsIndex); + popup->insertItem(KIcon(service.m_strIcon), service.m_strName, actionsIndex); } m_actionsVector.append(service); @@ -529,6 +516,74 @@ void InfoSidebarPage::insertActions() } } +void InfoSidebarPage::showAnnotation(const KUrl& file) +{ + if(m_metadata->storageUp()) { + QString text = m_metadata->annotation(file); + if (!text.isEmpty()) { + m_annotationLabel->show(); + m_annotationLabel->setText(QString("%1 :
%2").arg(i18n("Annotation")).arg(text)); + m_annotationButton->setText(i18n("Change annotation")); + } else { + m_annotationLabel->hide(); + m_annotationButton->setText(i18n("Annotate file")); + } + } +} + +void InfoSidebarPage::showAnnotations(const KUrl::List& files) +{ + if (m_metadata->storageUp()) { + bool hasAnnotation = false; + unsigned int annotateNum = 0; + QString firsts = QString("%1 :
").arg(i18n("Annotations")); + foreach (KUrl file, files) { + QString annotation = m_metadata->annotation(file); + if (!annotation.isEmpty()) { + hasAnnotation = true; + if (annotateNum < 3) { + // don't show more than 3 annotations + firsts += m_annotationLabel->fontMetrics().elidedText(QString("%1 : %2
").arg(file.fileName()).arg(annotation), Qt::ElideRight, width());//FIXME not really the good method, does not handle resizing ... + annotateNum++; + } + } + } + if (hasAnnotation) { + m_annotationLabel->show(); + m_annotationLabel->setText(firsts); + } + else { + m_annotationLabel->hide(); + } + m_annotationButton->setText(hasAnnotation ? i18n("Change annotations") : i18n("Annotate files")); + } +} + +void InfoSidebarPage::changeAnnotation() +{ + bool ok = false; + KUrl::List files(mainWindow()->activeView()->selectedItems().urlList()); + QString name, old; + if (files.isEmpty()) { + files << m_shownUrl; + } + else if (files.count() == 1) { + name = files[0].url(); + old = m_metadata->annotation(files[0]); + } + else { + name = QString("%1 files").arg(files.count()); + old = QString(); + } + QString text = QInputDialog::getText(this, "Annotate", QString("Set annotation for %1").arg(name), QLineEdit::Normal, old, &ok);//FIXME temporary, must move to a real dialog + if(ok) { + foreach(KUrl file, files) { + m_metadata->setAnnotation(file, text); + } + showAnnotation(files[0]); + } +} + ServiceButton::ServiceButton(const QIcon& icon, const QString& text, QWidget* parent, @@ -549,6 +604,7 @@ ServiceButton::~ServiceButton() void ServiceButton::paintEvent(QPaintEvent* event) { + Q_UNUSED(event); QPainter painter(this); const int buttonWidth = width(); const int buttonHeight = height(); @@ -574,9 +630,9 @@ void ServiceButton::paintEvent(QPaintEvent* event) // draw icon int x = spacing; const int y = (buttonHeight - K3Icon::SizeSmall) / 2; - const QIcon* set = iconSet(); - if (set != 0) { - painter.drawPixmap(x, y, set->pixmap(QIcon::Small, QIcon::Normal)); + const QIcon &set = icon(); + if (!set.isNull()) { + painter.drawPixmap(x, y, set.pixmap(QIcon::Small, QIcon::Normal)); } x += K3Icon::SizeSmall + spacing;