int DolphinApplication::newInstance()
{
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
- static bool first = true;
- switch (args->count()) {
- case 0:
- if( !first || !isSessionRestored()) {
- openWindow(KUrl());
- }
- break;
-
- case 1:
- openWindow(args->url(0));
- break;
-
- case 2:
- openSplitWindow(args->url(0),args->url(1));
- break;
+ QList<KUrl> urls;
+ const int argsCount = args->count();
+ for (int i = 0; i < argsCount; ++i) {
+ urls.append(args->url(i));
+ }
- default:
- for (int i = 0; i < args->count(); ++i) {
- openWindow(args->url(i));
+ DolphinMainWindow* win = createMainWindow();
+ if (urls.count() > 0) {
+ if (args->isSet("select")) {
+ win->openFiles(urls);
+ } else {
+ win->openDirectories(urls);
}
}
+ win->show();
- first = false;
args->clear();
return 0;
}
-int DolphinApplication::openWindow(const KUrl& url)
+int DolphinApplication::openWindow(const QString& urlString)
{
DolphinMainWindow* win = createMainWindow();
- if ((win->activeViewContainer() != 0) && url.isValid()) {
- win->activeViewContainer()->setUrl(url);
+ const KUrl url(urlString);
+ if (!url.isEmpty()) {
+ win->openDirectories(QList<KUrl>() << url);
}
win->show();
return win->getId();
}
-int DolphinApplication::openSplitWindow(const KUrl& leftUrl, const KUrl& rightUrl)
-{
- DolphinMainWindow* win = createMainWindow();
- if ((win->activeViewContainer() != 0) && leftUrl.isValid()) {
- win->activeViewContainer()->setUrl(leftUrl);
- }
- win->toggleSplitView();
- if ((win->activeViewContainer() != 0) && rightUrl.isValid()){
- win->activeViewContainer()->setUrl(rightUrl);
- }
- win->show();
- return win->getId();
-}
-
-
#include "dolphinapplication.moc"
#define _DOLPHIN_APPLICATION_H
#include <kuniqueapplication.h>
-#include <kurl.h>
class DolphinMainWindow;
class KUrl;
/** @see KUniqueApplication::newInstance(). */
virtual int newInstance();
-public slots:
- int openWindow(const KUrl& url);
- int openSplitWindow(const KUrl& leftUrl,const KUrl& rightUrl);
+ /** Interface implementation for D-Bus Interface. */
+ int openWindow(const QString& urlString);
-protected:
+private:
/** Called by the DolphinMainWindow to deregister. */
void removeMainWindow(DolphinMainWindow* mainWindow);
DolphinApplication::app()->removeMainWindow(this);
}
+void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
+{
+ if (dirs.isEmpty()) {
+ return;
+ }
+
+ const int oldOpenTabsCount = m_viewTab.count();
+
+ const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
+ const bool hasSplitView = generalSettings->splitView();
+
+ // Open each directory inside a new tab. If the "split view" option has been enabled,
+ // always show two directories within one tab.
+ QList<KUrl>::const_iterator it = dirs.begin();
+ while (it != dirs.end()) {
+ openNewTab(*it);
+ ++it;
+
+ if (hasSplitView && (it != dirs.end())) {
+ const int tabIndex = m_viewTab.count() - 1;
+ m_viewTab[tabIndex].secondaryView->setUrl(*it);
+ ++it;
+ }
+ }
+
+ // remove the previously opened tabs
+ for (int i = 0; i < oldOpenTabsCount; ++i) {
+ closeTab(0);
+ }
+}
+
+void DolphinMainWindow::openFiles(const QList<KUrl>& files)
+{
+ // Get all distinct directories from 'files' and open a tab
+ // for each directory. If the "split view" option is enabled, two
+ // directories are shown inside one tab (see openDirectories()).
+ QList<KUrl> dirs;
+ foreach (const KUrl& url, files) {
+ const KUrl dir(url.directory());
+ if (!dirs.contains(dir)) {
+ dirs.append(dir);
+ }
+ }
+
+ openDirectories(dirs);
+
+ // Select the files. Although the files can be split between several
+ // tabs, there is no need to split 'files' accordingly, as
+ // the DolphinView will just ignore invalid selections.
+ const int tabCount = m_viewTab.count();
+ for (int i = 0; i < tabCount; ++i) {
+ m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
+ if (m_viewTab[i].secondaryView != 0) {
+ m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
+ }
+ }
+}
+
void DolphinMainWindow::toggleViews()
{
if (m_viewTab[m_tabIndex].primaryView == 0) {
}
}
-void DolphinMainWindow::changeSelection(const KFileItemList& selection)
-{
- activeViewContainer()->view()->changeSelection(selection);
-}
-
void DolphinMainWindow::slotEditableStateChanged(bool editable)
{
KToggleAction* editableLocationAction =
foldersPanel, SLOT(setUrl(KUrl)));
connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
- connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
- this, SLOT(changeSelection(KFileItemList)));
// setup "Terminal"
#ifndef Q_OS_WIN
*/
DolphinViewContainer* activeViewContainer() const;
+ /**
+ * Opens each directory \p in a separate tab. If the "split view"
+ * option is enabled, 2 directories are collected within one tab.
+ */
+ void openDirectories(const QList<KUrl>& dirs);
+
+ /**
+ * Opens the directory which contains the files \p files
+ * and selects all files (implements the --select option
+ * of Dolphin).
+ */
+ void openFiles(const QList<KUrl>& files);
+
/**
* Returns true, if the main window contains two instances
* of a view container. The active view constainer can be
int getId() const;
/**
+ * Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
* Inform all affected dolphin components (panels, views) of an URL
* change.
*/
void changeUrl(const KUrl& url);
- /**
- * Inform all affected dolphin components that a selection change is
- * requested.
- */
- void changeSelection(const KFileItemList& selection);
-
/** Stores all settings and quits Dolphin. */
void quit();
return view && view->selectionModel()->hasSelection();
}
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
+{
+ foreach (const KUrl& url, urls) {
+ KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+ m_selectedItems.append(item);
+ }
+}
+
KFileItemList DolphinView::selectedItems() const
{
const QAbstractItemView* view = m_viewAccessor.itemView();
QByteArray viewState;
QDataStream saveStream(&viewState, QIODevice::WriteOnly);
saveState(saveStream);
- m_selectedItems = selectedItems();
+ m_selectedItems= selectedItems();
setUrl(url());
loadDirectory(url(), true);
m_viewAccessor.itemView()->clearSelection();
}
-void DolphinView::changeSelection(const KFileItemList& selection)
-{
- clearSelection();
- if (selection.isEmpty()) {
- return;
- }
- const KUrl& baseUrl = url();
- KUrl url;
- QItemSelection newSelection;
- foreach(const KFileItem& item, selection) {
- url = item.url().upUrl();
- if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
- QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
- newSelection.select(index, index);
- }
- }
- m_viewAccessor.itemView()->selectionModel()->select(newSelection,
- QItemSelectionModel::ClearAndSelect
- | QItemSelectionModel::Current);
-}
-
void DolphinView::renameSelectedItems()
{
KFileItemList items = selectedItems();
}
if (!m_selectedItems.isEmpty()) {
- changeSelection(m_selectedItems);
+ const KUrl& baseUrl = url();
+ KUrl url;
+ QItemSelection newSelection;
+ foreach(const KFileItem& item, m_selectedItems) {
+ url = item.url().upUrl();
+ if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+ newSelection.select(index, index);
+ }
+ }
+ m_viewAccessor.itemView()->selectionModel()->select(newSelection,
+ QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Current);
m_selectedItems.clear();
}
*/
bool supportsCategorizedSorting() const;
+ /**
+ * Marks the items indicated by \p urls to get selected after the
+ * directory DolphinView::url() has been loaded. Note that nothing
+ * gets selected if no loading of a directory has been triggered
+ * by DolphinView::setUrl() or DolphinView::reload().
+ */
+ void markUrlsAsSelected(const QList<KUrl>& urls);
+
/**
* Returns the selected items. The list is empty if no item has been
* selected.
void clearSelection();
- /**
- * Request of a selection change. The view will do its best to accommodate
- * the request, but it is not guaranteed that all items in \a selection
- * will actually get selected. The view will e.g. not select items which
- * are not in the currently displayed folder.
- */
- void changeSelection(const KFileItemList& selection);
-
/**
* Triggers the renaming of the currently selected items, where
* the user must input a new name for the items.
KCmdLineArgs::init(argc, argv, &about);
KCmdLineOptions options;
- options.add("+[Url]", ki18nc("@info:shell", "Document to open"));
+
+ // TODO KDE SC 4.5: The string freeze is valid and no new localized strings are allowed.
+ // To get in the --select option that was available in Konqueror 3, an already existing
+ // string ("Document to open") is used as workaround (the --select option will most probably
+ // anyhow used by applications and not by users).
+ const KLocalizedString& documentToOpen = ki18nc("@info:shell", "Document to open");
+ options.add("select", documentToOpen);
+ options.add("+[Url]", documentToOpen);
KCmdLineArgs::addCmdLineOptions(options);
if (!DolphinApplication::start()) {
if (index.isValid()) {
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
- emit changeSelection(KFileItemList());
}
TreeViewContextMenu contextMenu(this, item);
*/
void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
- /**
- * This signal is emitted when the panel requests a change in the
- * current selection. The file-management view recieving this signal is
- * not required to select all listed files, limiting the selection to
- * e.g. the current folder. The new selection will be reported via the
- * setSelection slot.
- */
- void changeSelection(const KFileItemList& selection);
-
public slots:
/**
* Changes the current selection inside the tree to \a url.