2006-11-21 06:02:05 +00:00
/***************************************************************************
2011-02-04 14:57:33 +00:00
* Copyright ( C ) 2006 by Peter Penz < peter . penz19 @ gmail . com > *
2006-11-21 06:02:05 +00:00
* Copyright ( C ) 2006 by Stefan Monov < logixoul @ gmail . com > *
2015-02-04 09:22:03 +00:00
* Copyright ( C ) 2015 by Mathieu Tarral < mathieu . tarral @ gmail . com > *
2006-11-21 06:02:05 +00:00
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU General Public License for more details . *
* *
* You should have received a copy of the GNU General Public License *
* along with this program ; if not , write to the *
* Free Software Foundation , Inc . , *
2006-12-08 21:24:08 +00:00
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA *
2006-11-21 06:02:05 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2018-03-04 13:38:16 +00:00
# include "dbusinterface.h"
# include "dolphin_generalsettings.h"
2015-07-29 20:54:54 +00:00
# include "dolphin_version.h"
2018-03-04 13:38:16 +00:00
# include "dolphindebug.h"
2007-09-27 12:36:40 +00:00
# include "dolphinmainwindow.h"
2015-04-22 13:29:39 +00:00
# include "global.h"
2007-09-27 12:36:40 +00:00
2015-02-04 09:22:03 +00:00
# include <KAboutData>
2015-11-14 21:37:40 +00:00
# include <KCrash>
2018-03-04 13:38:16 +00:00
# include <KDBusService>
2014-10-18 12:42:41 +00:00
# include <KLocalizedString>
2015-04-27 11:01:18 +00:00
# include <Kdelibs4ConfigMigrator>
2006-11-21 06:02:05 +00:00
2018-03-04 13:38:16 +00:00
# include <QApplication>
# include <QCommandLineParser>
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
# include <QDBusConnection>
# include <QDBusInterface>
# include <QDBusAbstractInterface>
# include <QDBusConnectionInterface>
2018-03-04 13:38:16 +00:00
2017-02-19 01:32:48 +00:00
# ifndef Q_OS_WIN
# include <unistd.h>
# endif
# include <iostream>
2014-11-08 21:50:38 +00:00
extern " C " Q_DECL_EXPORT int kdemain ( int argc , char * * argv )
2006-11-21 06:02:05 +00:00
{
2017-02-19 01:32:48 +00:00
# ifndef Q_OS_WIN
Re-allow running Dolphin as the root user (but still not using sudo)
Summary:
Prohibiting the use of Dolphin as the actual root user (not using `sudo` or `kdesu`) breaks legitimate use cases for using the root user. An example is Kali, a distro that logs in as the root user by default as a deliberate design choice.
In such an environment, there is no additional security vulnerability beyond what you're already potentially exposing yourself to. So, let's re-enable it.
BUG: 387974
FIXED-IN: 18.08.0
Test Plan:
- Log in as normal user and run `sudo dolphin`: you get an error message.
- Log in as normal user and run `kdesu dolphin`: you get an error message.
- Log in as the root user and run dolphin normally: it works.
Reviewers: markg, elvisangelaccio, #dolphin
Reviewed By: markg
Subscribers: chinmoyr, cfeck, elvisangelaccio, mmustac, Fuchs, markg, graesslin, nicolasfella, zzag, kfm-devel, emmanuelp
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D12795
2018-05-09 23:18:08 +00:00
// Prohibit using sudo or kdesu (but allow using the root user directly)
2017-02-19 01:32:48 +00:00
if ( getuid ( ) = = 0 ) {
Re-allow running Dolphin as the root user (but still not using sudo)
Summary:
Prohibiting the use of Dolphin as the actual root user (not using `sudo` or `kdesu`) breaks legitimate use cases for using the root user. An example is Kali, a distro that logs in as the root user by default as a deliberate design choice.
In such an environment, there is no additional security vulnerability beyond what you're already potentially exposing yourself to. So, let's re-enable it.
BUG: 387974
FIXED-IN: 18.08.0
Test Plan:
- Log in as normal user and run `sudo dolphin`: you get an error message.
- Log in as normal user and run `kdesu dolphin`: you get an error message.
- Log in as the root user and run dolphin normally: it works.
Reviewers: markg, elvisangelaccio, #dolphin
Reviewed By: markg
Subscribers: chinmoyr, cfeck, elvisangelaccio, mmustac, Fuchs, markg, graesslin, nicolasfella, zzag, kfm-devel, emmanuelp
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D12795
2018-05-09 23:18:08 +00:00
if ( ! qEnvironmentVariableIsEmpty ( " SUDO_USER " ) ) {
std : : cout < < " Executing Dolphin with sudo is not possible due to unfixable security vulnerabilities. " < < std : : endl ;
return EXIT_FAILURE ;
} else if ( ! qEnvironmentVariableIsEmpty ( " KDESU_USER " ) ) {
std : : cout < < " Executing Dolphin with kdesu is not possible due to unfixable security vulnerabilities. " < < std : : endl ;
return EXIT_FAILURE ;
}
2017-02-19 01:32:48 +00:00
}
# endif
2015-02-04 09:22:03 +00:00
QApplication app ( argc , argv ) ;
2015-03-25 11:38:02 +00:00
app . setAttribute ( Qt : : AA_UseHighDpiPixmaps , true ) ;
2016-11-22 16:55:34 +00:00
app . setWindowIcon ( QIcon : : fromTheme ( QStringLiteral ( " system-file-manager " ) , app . windowIcon ( ) ) ) ;
2015-04-27 11:01:18 +00:00
2015-11-14 21:37:40 +00:00
KCrash : : initialize ( ) ;
2015-02-06 08:32:39 +00:00
Kdelibs4ConfigMigrator migrate ( QStringLiteral ( " dolphin " ) ) ;
migrate . setConfigFiles ( QStringList ( ) < < QStringLiteral ( " dolphinrc " ) ) ;
migrate . setUiFiles ( QStringList ( ) < < QStringLiteral ( " dolphinpart.rc " ) < < QStringLiteral ( " dolphinui.rc " ) ) ;
migrate . migrate ( ) ;
2015-11-29 18:19:33 +00:00
KLocalizedString : : setApplicationDomain ( " dolphin " ) ;
2016-03-16 21:17:37 +00:00
KAboutData aboutData ( QStringLiteral ( " dolphin " ) , i18n ( " Dolphin " ) , QStringLiteral ( DOLPHIN_VERSION_STRING ) ,
2015-02-04 09:22:03 +00:00
i18nc ( " @title " , " File Manager " ) ,
KAboutLicense : : GPL ,
2018-11-11 18:00:24 +00:00
i18nc ( " @info:credit " , " (C) 2006-2018 Peter Penz, Frank Reininghaus, Emmanuel Pescosta and Elvis Angelaccio " ) ) ;
2019-01-04 21:22:07 +00:00
aboutData . setHomepage ( QStringLiteral ( " https://dolphin.kde.org " ) ) ;
2018-11-04 20:21:19 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Elvis Angelaccio " ) ,
i18nc ( " @info:credit " , " Maintainer (since 2018) and developer " ) ,
QStringLiteral ( " elvis.angelaccio@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Emmanuel Pescosta " ) ,
2018-11-04 20:21:19 +00:00
i18nc ( " @info:credit " , " Maintainer (2014-2018) and developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " emmanuelpescosta099@gmail.com " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Frank Reininghaus " ) ,
i18nc ( " @info:credit " , " Maintainer (2012-2014) and developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " frank78ac@googlemail.com " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Peter Penz " ) ,
i18nc ( " @info:credit " , " Maintainer and developer (2006-2012) " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " peter.penz19@gmail.com " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Sebastian Trüg " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " trueg@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " David Faure " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " faure@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Aaron J. Seigo " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " aseigo@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Rafael Fernández López " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " ereslibre@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Kevin Ottens " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " ervin@kde.org " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Holger Freyther " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " freyther@gmx.net " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Max Blazejak " ) ,
i18nc ( " @info:credit " , " Developer " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " m43ksrocks@gmail.com " ) ) ;
2015-02-04 09:22:03 +00:00
aboutData . addAuthor ( i18nc ( " @info:credit " , " Michael Austin " ) ,
i18nc ( " @info:credit " , " Documentation " ) ,
2016-03-16 21:17:37 +00:00
QStringLiteral ( " tuxedup@users.sourceforge.net " ) ) ;
2015-02-04 09:22:03 +00:00
KAboutData : : setApplicationData ( aboutData ) ;
2015-02-04 09:29:33 +00:00
KDBusService dolphinDBusService ;
2015-04-22 13:29:39 +00:00
DBusInterface interface ;
2015-02-04 09:29:33 +00:00
2015-02-04 09:22:03 +00:00
QCommandLineParser parser ;
aboutData . setupCommandLine ( & parser ) ;
// command line options
2016-05-05 11:43:02 +00:00
parser . addOption ( QCommandLineOption ( QStringList ( ) < < QStringLiteral ( " select " ) , i18nc ( " @info:shell " , " The files and folders passed as arguments "
2015-02-04 09:22:03 +00:00
" will be selected. " ) ) ) ;
2016-03-16 21:17:37 +00:00
parser . addOption ( QCommandLineOption ( QStringList ( ) < < QStringLiteral ( " split " ) , i18nc ( " @info:shell " , " Dolphin will get started with a split view. " ) ) ) ;
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
parser . addOption ( QCommandLineOption ( QStringList ( ) < < QStringLiteral ( " new-window " ) , i18nc ( " @info:shell " , " Dolphin will explicitly open in a new window. " ) ) ) ;
2016-03-16 21:17:37 +00:00
parser . addOption ( QCommandLineOption ( QStringList ( ) < < QStringLiteral ( " daemon " ) , i18nc ( " @info:shell " , " Start Dolphin Daemon (only required for DBus Interface) " ) ) ) ;
parser . addPositionalArgument ( QStringLiteral ( " +[Url] " ) , i18nc ( " @info:shell " , " Document to open " ) ) ;
2015-02-04 09:22:03 +00:00
parser . process ( app ) ;
aboutData . processCommandLine ( & parser ) ;
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
const bool splitView = parser . isSet ( QStringLiteral ( " split " ) ) | | GeneralSettings : : splitView ( ) ;
const bool openFiles = parser . isSet ( QStringLiteral ( " select " ) ) ;
const QStringList args = parser . positionalArguments ( ) ;
QList < QUrl > urls = Dolphin : : validateUris ( args ) ;
2016-03-16 21:17:37 +00:00
if ( parser . isSet ( QStringLiteral ( " daemon " ) ) ) {
2015-04-22 13:29:39 +00:00
return app . exec ( ) ;
}
2015-02-04 09:22:03 +00:00
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
if ( ! parser . isSet ( QStringLiteral ( " new-window " ) ) ) {
if ( Dolphin : : attachToExistingInstance ( urls , openFiles , splitView ) ) {
// Successfully attached to existing instance of Dolphin
return 0 ;
}
}
2019-06-22 13:44:11 +00:00
if ( urls . isEmpty ( ) ) {
// We need at least one URL to open Dolphin
urls . append ( Dolphin : : homeUrl ( ) ) ;
}
2019-08-25 16:26:39 +00:00
if ( splitView & & urls . size ( ) < 2 ) {
// Split view does only make sense if we have at least 2 URLs
urls . append ( urls . last ( ) ) ;
}
2015-04-27 11:01:18 +00:00
DolphinMainWindow * mainWindow = new DolphinMainWindow ( ) ;
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
if ( openFiles ) {
2015-04-27 11:01:18 +00:00
mainWindow - > openFiles ( urls , splitView ) ;
2015-04-27 10:55:53 +00:00
} else {
2015-04-27 11:01:18 +00:00
mainWindow - > openDirectories ( urls , splitView ) ;
2015-02-04 09:22:03 +00:00
}
2015-04-27 11:01:18 +00:00
mainWindow - > show ( ) ;
2015-02-04 09:22:03 +00:00
if ( app . isSessionRestored ( ) ) {
const QString className = KXmlGuiWindow : : classNameOfToplevel ( 1 ) ;
if ( className = = QLatin1String ( " DolphinMainWindow " ) ) {
2015-04-27 11:01:18 +00:00
mainWindow - > restore ( 1 ) ;
2015-02-04 09:22:03 +00:00
} else {
2015-02-24 16:07:55 +00:00
qCWarning ( DolphinDebug ) < < " Unknown class " < < className < < " in session saved data! " ;
2012-12-05 20:44:06 +00:00
}
2007-04-09 19:12:54 +00:00
}
2007-09-27 12:36:40 +00:00
2015-02-04 09:22:03 +00:00
return app . exec ( ) ; // krazy:exclude=crash;
2007-09-27 12:36:40 +00:00
}