+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("<b>%1</b> :<br/>%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;
+ if (m_metadata->storageUp()) {
+ bool hasAnnotation = false;
+ unsigned int annotateNum = 0;
+ QString firsts("<b>%1 :</b><br/>");
+ firsts.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("<b>%1</b> : %2<br/>").arg(file.fileName()).arg(annotation), Qt::ElideRight, width());
+ 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]);
+ }
+}
+