]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/infosidebarpage.cpp
For all Zecke thoughts a nice solution could be found during the last weeks :-)
[dolphin.git] / src / infosidebarpage.cpp
index efc85cc71ed9bb847797cd7ebf1a2d5842d64532..61a7b06438560694b2a6a3f377d2b6c6a7a95a4a 100644 (file)
 #include <qtimer.h>
 #include <qpushbutton.h>
 
-#include <q3vgroupbox.h>
 #include <q3popupmenu.h>
 #include <qpainter.h>
 #include <qfontmetrics.h>
-#include <q3grid.h>
-#include <q3hgroupbox.h>
-//Added by qt3to4:
 #include <Q3ValueList>
 #include <QEvent>
-#include <Q3VBoxLayout>
 #include <QInputDialog>
 
 #include <kbookmarkmanager.h>
@@ -47,6 +42,7 @@
 #include <kglobalsettings.h>
 #include <kfilemetainfo.h>
 #include <kvbox.h>
+#include <kseparator.h>
 
 #include "dolphinmainwindow.h"
 #include "dolphinapplication.h"
@@ -86,15 +82,17 @@ 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_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);
@@ -103,14 +101,9 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent)
         m_annotationButton = new QPushButton("", this);
         m_annotationButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
         connect(m_annotationButton, SIGNAL(released()), this, SLOT(changeAnnotation()));
+        sep3 = new KSeparator(this);
     }
 
-    QWidget* sep2 = new Q3HGroupBox(this);  // TODO: check whether default widget exist for this?
-    sep2->setFixedHeight(1);
-
-    QWidget* sep3 = new Q3HGroupBox(this);  // TODO: check whether default widget exist for this?
-    sep3->setFixedHeight(1);
-
     // actions
     m_actionBox = new KVBox(this);
     m_actionBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
@@ -178,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",
@@ -190,10 +187,10 @@ 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());
@@ -213,7 +210,7 @@ void InfoSidebarPage::showItemInfo()
                 this, SLOT(slotPreviewFailed(const KFileItem*)));
 
         QString text("<b>");
-        text.append(m_shownUrl.fileName());
+        text.append(file.fileName());
         text.append("</b>");
         m_name->setText(text);
     }
@@ -231,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));
     }
 }
@@ -271,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("<b>");
             text.append(bookmark.text());
             text.append("</b>");
@@ -328,7 +325,7 @@ void InfoSidebarPage::createMetaInfo()
             for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) {
                 if (showMetaInfo(*it)) {
                     KFileMetaInfoItem metaInfoItem = metaInfo.item(*it);
-                    addInfoLine(*it, metaInfoItem.string());
+                    addInfoLine(*it, metaInfoItem.value().toString());
                 }
             }
         }
@@ -522,7 +519,7 @@ void InfoSidebarPage::insertActions()
 void InfoSidebarPage::showAnnotation(const KUrl& file)
 {
     if(m_metadata->storageUp()) {
-        QString text = m_metadata->getAnnotation(file);
+        QString text = m_metadata->annotation(file);
         if (!text.isEmpty()) {
             m_annotationLabel->show();
             m_annotationLabel->setText(QString("<b>%1</b> :<br/>%2").arg(i18n("Annotation")).arg(text));
@@ -536,18 +533,17 @@ void InfoSidebarPage::showAnnotation(const KUrl& file)
 
 void InfoSidebarPage::showAnnotations(const KUrl::List& files)
 {
-    static unsigned int maxShownAnnot = 3;
     if (m_metadata->storageUp()) {
         bool hasAnnotation = false;
         unsigned int annotateNum = 0;
-        QString firsts("<b>%1 :</b><br/>");
-        firsts.arg(i18n("Annotations"));
+        QString firsts = QString("<b>%1 :</b><br/>").arg(i18n("Annotations"));
         foreach (KUrl file, files) {
-            QString annotation = m_metadata->getAnnotation(file);
+            QString annotation = m_metadata->annotation(file);
             if (!annotation.isEmpty()) {
                 hasAnnotation = true;
-                if(annotateNum < maxShownAnnot) {
-                    firsts += m_annotationLabel->fontMetrics().elidedText(QString("<b>%1</b> : %2<br/>").arg(file.fileName()).arg(annotation), Qt::ElideRight, width());
+                if (annotateNum < 3) {
+                    // don't show more than 3 annotations
+                    firsts += m_annotationLabel->fontMetrics().elidedText(QString("<b>%1</b> : %2<br/>").arg(file.fileName()).arg(annotation), Qt::ElideRight, width());//FIXME not really the good method, does not handle resizing ...
                     annotateNum++;
                 }
             }
@@ -555,7 +551,10 @@ void InfoSidebarPage::showAnnotations(const KUrl::List& files)
         if (hasAnnotation) {
             m_annotationLabel->show();
             m_annotationLabel->setText(firsts);
-        } else m_annotationLabel->hide();
+        }
+        else {
+            m_annotationLabel->hide();
+        }
         m_annotationButton->setText(hasAnnotation ? i18n("Change annotations") : i18n("Annotate files"));
     }
 }
@@ -570,7 +569,7 @@ void InfoSidebarPage::changeAnnotation()
     }
     else if (files.count() == 1) {
         name = files[0].url();
-        old = m_metadata->getAnnotation(files[0]);
+        old = m_metadata->annotation(files[0]);
     }
     else {
         name = QString("%1 files").arg(files.count());
@@ -605,6 +604,7 @@ ServiceButton::~ServiceButton()
 
 void ServiceButton::paintEvent(QPaintEvent* event)
 {
+    Q_UNUSED(event);
     QPainter painter(this);
     const int buttonWidth  = width();
     const int buttonHeight = height();