X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/01b5b16a3f35065633a34584a720842f0df3a8fa..5b5a7b8da8cb3ee6bbb9f7450c87fca5de41dc05:/src/infosidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index c05f5a8f8..42352429b 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -20,22 +20,20 @@ #include #include "infosidebarpage.h" -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include -#include +#include #include #include #include @@ -45,25 +43,25 @@ #include #include #include +#include #ifdef HAVE_KMETADATA #include #endif -#include "dolphinmainwindow.h" -#include "dolphinapplication.h" #include "pixmapviewer.h" #include "dolphinsettings.h" #include "metadatawidget.h" -InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) : - SidebarPage(mainWindow, parent), - m_multipleSelection(false), - m_pendingPreview(false), - m_timer(0), - m_preview(0), - m_name(0), - m_infos(0) +InfoSidebarPage::InfoSidebarPage(QWidget* parent) : + SidebarPage(parent), + m_multipleSelection(false), //TODO:check if I'm needed + m_pendingPreview(false), + m_timer(0), + m_currentSelection(KFileItemList()), + m_preview(0), + m_name(0), + m_infos(0) { const int spacing = KDialog::spacingHint(); @@ -96,8 +94,8 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) KSeparator* sep2 = new KSeparator(this); - if ( MetaDataWidget::metaDataAvailable() ) - m_metadataWidget = new MetaDataWidget( this ); + if (MetaDataWidget::metaDataAvailable()) + m_metadataWidget = new MetaDataWidget(this); else m_metadataWidget = 0; @@ -105,36 +103,40 @@ InfoSidebarPage::InfoSidebarPage(DolphinMainWindow* mainWindow, QWidget* parent) m_actionBox = new KVBox(this); m_actionBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - // Add a dummy widget with no restriction regarding a vertical resizing. - // This assures that information is always top aligned. - QWidget* dummy = new QWidget(this); - layout->addItem(new QSpacerItem(spacing, spacing, QSizePolicy::Preferred, QSizePolicy::Fixed)); layout->addWidget(m_preview); layout->addWidget(m_name); layout->addWidget(sep1); layout->addWidget(m_infos); layout->addWidget(sep2); - if ( m_metadataWidget ) { - layout->addWidget( m_metadataWidget ); - layout->addWidget( new KSeparator( this ) ); + if (m_metadataWidget) { + layout->addWidget(m_metadataWidget); + layout->addWidget(new KSeparator(this)); } layout->addWidget(m_actionBox); - layout->addWidget(dummy); + // ensure that widgets in the information side bar are aligned towards the top + layout->addStretch(1); setLayout(layout); - connect(mainWindow, SIGNAL(selectionChanged()), - this, SLOT(showItemInfo())); - - connectToActiveView(); } InfoSidebarPage::~InfoSidebarPage() +{} + +void InfoSidebarPage::setUrl(const KUrl& url) { + if (!m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { + cancelRequest(); + m_shownUrl = url; + showItemInfo(); + } } -void InfoSidebarPage::activeViewChanged() +void InfoSidebarPage::setSelection(const KFileItemList& selection) { - connectToActiveView(); + cancelRequest(); + m_currentSelection = selection; + m_multipleSelection = (m_currentSelection.size() > 1); + showItemInfo(); } void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url) @@ -148,29 +150,13 @@ void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url) } } -void InfoSidebarPage::requestItemInfo(const KUrl& url) -{ - cancelRequest(); - - if (!url.isEmpty() && !m_multipleSelection) { - m_shownUrl = url; - showItemInfo(); - } -} - void InfoSidebarPage::showItemInfo() { cancelRequest(); - m_multipleSelection = false; - - // show the preview... - DolphinView* view = mainWindow()->activeView(); - const KFileItemList selectedItems = view->selectedItems(); + KFileItemList selectedItems = m_currentSelection; KUrl file; - if (selectedItems.count() > 1) { - m_multipleSelection = true; - } else if(selectedItems.count() == 0) { + if (selectedItems.count() == 0) { file = m_shownUrl; } else { file = selectedItems[0]->url(); @@ -181,9 +167,8 @@ void InfoSidebarPage::showItemInfo() K3Icon::NoGroup, K3Icon::SizeEnormous); m_preview->setPixmap(icon); - m_name->setText(i18n("%1 items selected",selectedItems.count())); - } - else if (!applyBookmark(file)) { + m_name->setText(i18n("%1 items selected", selectedItems.count())); + } else if (!applyBookmark(file)) { // try to get a preview pixmap from the item... KUrl::List list; list.append(file); @@ -229,9 +214,10 @@ void InfoSidebarPage::slotPreviewFailed(const KFileItem* item) } } -void InfoSidebarPage::gotPreview(const KFileItem* /* item */, +void InfoSidebarPage::gotPreview(const KFileItem* item, const QPixmap& pixmap) { + Q_UNUSED(item); if (m_pendingPreview) { m_preview->setPixmap(pixmap); m_pendingPreview = false; @@ -240,49 +226,32 @@ void InfoSidebarPage::gotPreview(const KFileItem* /* item */, void InfoSidebarPage::startService(int index) { - DolphinView* view = mainWindow()->activeView(); - if (view->hasSelection()) { - KUrl::List selectedUrls = view->selectedUrls(); - KDEDesktopMimeType::executeService(selectedUrls, m_actionsVector[index]); - } - else { - KDEDesktopMimeType::executeService(m_shownUrl, m_actionsVector[index]); + if (m_currentSelection.count() > 0) { + // TODO: Use "at()" as soon as executeService is fixed to take a const param (BIC) + KDesktopFileActions::executeService(m_currentSelection.urlList(), m_actionsVector[index]); + } else { + // TODO: likewise + KDesktopFileActions::executeService(m_shownUrl, m_actionsVector[index]); } } -void InfoSidebarPage::connectToActiveView() +bool InfoSidebarPage::applyBookmark(const KUrl& url) { - cancelRequest(); - - DolphinView* view = mainWindow()->activeView(); - connect(view, SIGNAL(requestItemInfo(const KUrl&)), - this, SLOT(requestDelayedItemInfo(const KUrl&))); - connect(view, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(requestItemInfo(const KUrl&))); + KFilePlacesModel *placesModel = DolphinSettings::instance().placesModel(); + int count = placesModel->rowCount(); - m_shownUrl = view->url(); - showItemInfo(); -} + for (int i = 0; i < count; ++i) { + QModelIndex index = placesModel->index(i, 0); -bool InfoSidebarPage::applyBookmark(const KUrl& url) -{ - KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); - KBookmark bookmark = root.first(); - while (!bookmark.isNull()) { - if (url.equals(bookmark.url(), KUrl::CompareWithoutTrailingSlash)) { + if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { QString text(""); - text.append(bookmark.text()); + text.append(placesModel->text(index)); text.append(""); m_name->setText(text); - KIconLoader iconLoader; - QPixmap icon = iconLoader.loadIcon(bookmark.icon(), - K3Icon::NoGroup, - K3Icon::SizeEnormous); - m_preview->setPixmap(icon); + m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); return true; } - bookmark = root.next(bookmark); } return false; @@ -297,19 +266,17 @@ void InfoSidebarPage::cancelRequest() void InfoSidebarPage::createMetaInfo() { beginInfoLines(); - DolphinView* view = mainWindow()->activeView(); - if (!view->hasSelection()) { + if (m_currentSelection.size() == 0) { KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); fileItem.refresh(); if (fileItem.isDir()) { addInfoLine(i18n("Type:"), i18n("Directory")); } - if ( MetaDataWidget::metaDataAvailable() ) - m_metadataWidget->setFile( fileItem.url() ); - } - else if (view->selectedItems().count() == 1) { - KFileItem* fileItem = view->selectedItems()[0]; + if (MetaDataWidget::metaDataAvailable()) + m_metadataWidget->setFile(fileItem.url()); + } else if (m_currentSelection.count() == 1) { + KFileItem* fileItem = m_currentSelection.at(0); addInfoLine(i18n("Type:"), fileItem->mimeComment()); QString sizeText(KIO::convertSize(fileItem->size())); @@ -326,13 +293,13 @@ void InfoSidebarPage::createMetaInfo() } } } - if ( MetaDataWidget::metaDataAvailable() ) - m_metadataWidget->setFile( fileItem->url() ); - } - else { - m_metadataWidget->setFiles( view->selectedItems().urlList() ); + if (MetaDataWidget::metaDataAvailable()) + m_metadataWidget->setFile(fileItem->url()); + } else { + if (MetaDataWidget::metaDataAvailable()) + m_metadataWidget->setFiles(m_currentSelection.urlList()); unsigned long int totSize = 0; - foreach(KFileItem* item, view->selectedItems()) { + foreach(KFileItem* item, m_currentSelection) { 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)); @@ -354,19 +321,19 @@ bool InfoSidebarPage::showMetaInfo(const QString& key) const { // sorted list of keys, where it's data should be shown static const char* keys[] = { - "Album", - "Artist", - "Author", - "Bitrate", - "Date", - "Dimensions", - "Genre", - "Length", - "Lines", - "Pages", - "Title", - "Words" - }; + "Album", + "Artist", + "Author", + "Bitrate", + "Date", + "Dimensions", + "Genre", + "Length", + "Lines", + "Pages", + "Title", + "Words" + }; // do a binary search for the key... int top = 0; @@ -376,11 +343,9 @@ bool InfoSidebarPage::showMetaInfo(const QString& key) const const int result = key.compare(keys[middle]); if (result < 0) { bottom = middle - 1; - } - else if (result > 0) { + } else if (result > 0) { top = middle + 1; - } - else { + } else { return true; } } @@ -397,17 +362,14 @@ void InfoSidebarPage::addInfoLine(const QString& labelText, const QString& infoT void InfoSidebarPage::insertActions() { - // delete all existing action widgets - // TODO: just use children() from QObject... - Q3PtrListIterator deleteIter(m_actionWidgets); + QListIterator deleteIter(m_actionBox->findChildren()); QWidget* widget = 0; - while ((widget = deleteIter.current()) != 0) { + while (deleteIter.hasNext()) { + widget = deleteIter.next(); widget->close(); widget->deleteLater(); - ++deleteIter; } - m_actionWidgets.clear(); m_actionsVector.clear(); int actionsIndex = 0; @@ -416,7 +378,7 @@ void InfoSidebarPage::insertActions() // of KFileItems. If no selection is given, a temporary KFileItem // by the given Url 'url' is created and added to the list. KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); - KFileItemList itemList = mainWindow()->activeView()->selectedItems(); + KFileItemList itemList = m_currentSelection; if (itemList.isEmpty()) { fileItem.refresh(); itemList.append(&fileItem); @@ -431,7 +393,7 @@ void InfoSidebarPage::insertActions() QStringList entries = dir.entryList(QStringList("*.desktop"), QDir::Files); for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) { - KConfigGroup cfg(KSharedConfig::openConfig( *dirIt + *entryIt, KConfig::OnlyLocal ), "Desktop Entry" ); + 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.readEntry("ServiceTypes", QStringList(), ','); for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) { @@ -468,11 +430,11 @@ void InfoSidebarPage::insertActions() } if (insert) { - const QString submenuName = cfg.readEntry( "X-KDE-Submenu" ); - Q3PopupMenu* popup = 0; + const QString submenuName = cfg.readEntry("X-KDE-Submenu"); + QMenu* popup = 0; if (!submenuName.isEmpty()) { // create a sub menu containing all actions - popup = new Q3PopupMenu(); + popup = new QMenu(); connect(popup, SIGNAL(activated(int)), this, SLOT(startService(int))); @@ -480,27 +442,24 @@ void InfoSidebarPage::insertActions() button->setFlat(true); button->setMenu(popup); button->show(); - m_actionWidgets.append(button); } - Q3ValueList userServices = - KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true); + QList userServices = + KDesktopFileActions::userDefinedServices(*dirIt + *entryIt, true); // iterate through all actions and add them to a widget - Q3ValueList::Iterator serviceIt; + QList::Iterator serviceIt; for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) { - KDEDesktopMimeType::Service service = (*serviceIt); + KDesktopFileActions::Service service = (*serviceIt); if (popup == 0) { ServiceButton* button = new ServiceButton(KIcon(service.m_strIcon), - service.m_strName, - m_actionBox, - actionsIndex); + service.m_strName, + m_actionBox, + actionsIndex); connect(button, SIGNAL(requestServiceStart(int)), this, SLOT(startService(int))); - m_actionWidgets.append(button); button->show(); - } - else { + } else { popup->insertItem(KIcon(service.m_strIcon), service.m_strName, actionsIndex); } @@ -520,9 +479,9 @@ ServiceButton::ServiceButton(const QIcon& icon, const QString& text, QWidget* parent, int index) : - QPushButton(icon, text, parent), - m_hover(false), - m_index(index) + QPushButton(icon, text, parent), + m_hover(false), + m_index(index) { setEraseColor(palette().brush(QPalette::Background).color()); setFocusPolicy(Qt::NoFocus); @@ -531,8 +490,7 @@ ServiceButton::ServiceButton(const QIcon& icon, } ServiceButton::~ServiceButton() -{ -} +{} void ServiceButton::paintEvent(QPaintEvent* event) { @@ -546,8 +504,7 @@ void ServiceButton::paintEvent(QPaintEvent* event) if (m_hover) { backgroundColor = KGlobalSettings::highlightColor(); foregroundColor = KGlobalSettings::highlightedTextColor(); - } - else { + } else { backgroundColor = palette().brush(QPalette::Background).color(); foregroundColor = KGlobalSettings::buttonTextColor(); }