X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/74bf01c3fdb68cdb865ea700b89188ff2f9f2a73..72d4a92e1045e7340e4f65e9e62a68bd2d442cd1:/src/infosidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index 9c400b198..c05f5a8f8 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ +#include + #include "infosidebarpage.h" #include @@ -44,11 +46,15 @@ #include #include +#ifdef HAVE_KMETADATA +#include +#endif + #include "dolphinmainwindow.h" #include "dolphinapplication.h" #include "pixmapviewer.h" #include "dolphinsettings.h" -#include "metadataloader.h" +#include "metadatawidget.h" InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : SidebarPage(mainWindow, parent), @@ -57,8 +63,7 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) m_timer(0), m_preview(0), m_name(0), - m_infos(0), - m_metadata(DolphinApplication::app()->metadataLoader()) + m_infos(0) { const int spacing = KDialog::spacingHint(); @@ -91,18 +96,10 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) 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); - } + if ( MetaDataWidget::metaDataAvailable() ) + m_metadataWidget = new MetaDataWidget( this ); + else + m_metadataWidget = 0; // actions m_actionBox = new KVBox(this); @@ -118,10 +115,9 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) layout->addWidget(sep1); layout->addWidget(m_infos); layout->addWidget(sep2); - if (m_metadata->storageUp()) { - layout->addWidget(m_annotationLabel); - layout->addWidget(m_annotationButton); - layout->addWidget(sep3); + if ( m_metadataWidget ) { + layout->addWidget( m_metadataWidget ); + layout->addWidget( new KSeparator( this ) ); } layout->addWidget(m_actionBox); layout->addWidget(dummy); @@ -309,7 +305,8 @@ void InfoSidebarPage::createMetaInfo() if (fileItem.isDir()) { addInfoLine(i18n("Type:"), i18n("Directory")); } - showAnnotation(m_shownUrl); + if ( MetaDataWidget::metaDataAvailable() ) + m_metadataWidget->setFile( fileItem.url() ); } else if (view->selectedItems().count() == 1) { KFileItem* fileItem = view->selectedItems()[0]; @@ -325,14 +322,15 @@ 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()); } } } - showAnnotation(fileItem->url()); + if ( MetaDataWidget::metaDataAvailable() ) + m_metadataWidget->setFile( fileItem->url() ); } else { - showAnnotations(view->selectedItems().urlList()); + m_metadataWidget->setFiles( 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 @@ -516,70 +514,7 @@ void InfoSidebarPage::insertActions() } } -void InfoSidebarPage::showAnnotation(const KUrl& file) -{ - if(m_metadata->storageUp()) { - QString text = m_metadata->getAnnotation(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) -{ - static unsigned int maxShownAnnot = 3; //The maximum number of show annotations when selecting multiple 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->getAnnotation(file); - if (!annotation.isEmpty()) { - hasAnnotation = true; - if(annotateNum < maxShownAnnot) { - 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->getAnnotation(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,