2015-02-07 00:32:25 +00:00
|
|
|
/*************************************************************************
|
2016-03-02 18:33:40 +00:00
|
|
|
* Copyright (C) 2008-2010 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-02-07 00:32:25 +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 3 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, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
2008-12-27 22:12:42 +00:00
|
|
|
|
2015-06-04 01:51:56 +01:00
|
|
|
#include "util/guihelpers.h"
|
2017-06-13 21:12:58 +01:00
|
|
|
#include "config.h"
|
2008-12-27 22:12:42 +00:00
|
|
|
|
2016-01-12 00:12:49 +00:00
|
|
|
#include <backend/corebackendmanager.h>
|
2010-03-21 10:50:44 +00:00
|
|
|
|
2017-09-14 20:42:43 +01:00
|
|
|
#include <QAction>
|
2009-11-23 18:27:21 +00:00
|
|
|
#include <QApplication>
|
2014-05-18 21:41:48 +01:00
|
|
|
#include <QFileInfo>
|
2015-06-12 13:11:29 +01:00
|
|
|
#include <QIcon>
|
2017-09-14 20:42:43 +01:00
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
2015-06-12 13:11:29 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
2014-05-18 21:41:48 +01:00
|
|
|
#include <QProcess>
|
2017-09-14 20:42:43 +01:00
|
|
|
#include <QRect>
|
2014-05-18 21:41:48 +01:00
|
|
|
#include <QStandardPaths>
|
2015-06-04 01:51:56 +01:00
|
|
|
#include <QString>
|
2017-09-14 20:42:43 +01:00
|
|
|
#include <QTreeWidget>
|
2010-02-17 19:39:24 +00:00
|
|
|
|
2015-06-04 01:51:56 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KMessageBox>
|
2008-12-27 22:12:42 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2009-11-23 18:27:21 +00:00
|
|
|
|
2015-06-12 13:11:29 +01:00
|
|
|
QIcon createFileSystemColor(FileSystem::Type type, quint32 size)
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
QPixmap pixmap(size, size);
|
|
|
|
QPainter painter(&pixmap);
|
|
|
|
painter.setPen(QColor(0, 0, 0));
|
2018-04-07 19:54:55 +01:00
|
|
|
painter.setBrush(Config::fileSystemColorCode(static_cast<int>(type)));
|
2015-07-13 15:17:41 +01:00
|
|
|
painter.drawRect(QRect(0, 0, pixmap.width() - 1, pixmap.height() - 1));
|
|
|
|
painter.end();
|
|
|
|
|
|
|
|
return QIcon(pixmap);
|
2015-06-12 13:11:29 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 10:50:44 +00:00
|
|
|
bool loadBackend()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
if (CoreBackendManager::self()->load(Config::backend()) == false) {
|
|
|
|
if (CoreBackendManager::self()->load(CoreBackendManager::defaultBackendName())) {
|
2018-01-31 18:50:33 +00:00
|
|
|
if (!Config::firstRun())
|
|
|
|
KMessageBox::sorry(nullptr,
|
2015-07-13 15:17:41 +01:00
|
|
|
xi18nc("@info", "<para>The configured backend plugin \"%1\" could not be loaded.</para>"
|
|
|
|
"<para>Loading the default backend plugin \"%2\" instead.</para>",
|
|
|
|
Config::backend(), CoreBackendManager::defaultBackendName()),
|
2016-08-15 16:57:43 +01:00
|
|
|
xi18nc("@title:window", "Error: Could Not Load Backend Plugin"));
|
2015-07-13 15:17:41 +01:00
|
|
|
Config::setBackend(CoreBackendManager::defaultBackendName());
|
|
|
|
} else {
|
2016-04-14 19:18:36 +01:00
|
|
|
KMessageBox::error(nullptr,
|
2015-07-13 15:17:41 +01:00
|
|
|
xi18nc("@info", "<para>Neither the configured (\"%1\") nor the default (\"%2\") backend "
|
|
|
|
"plugin could be loaded.</para><para>Please check your installation.</para>",
|
|
|
|
Config::backend(), CoreBackendManager::defaultBackendName()),
|
2016-07-18 02:21:14 +01:00
|
|
|
xi18nc("@title:window", "Error: Could Not Load Backend Plugin"));
|
2015-07-13 15:17:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-03-21 10:50:44 +00:00
|
|
|
}
|
2015-06-04 01:51:56 +01:00
|
|
|
|
2015-06-14 02:03:13 +01:00
|
|
|
Capacity::Unit preferredUnit()
|
|
|
|
{
|
2015-07-13 15:17:41 +01:00
|
|
|
return static_cast<Capacity::Unit>(Config::preferredUnit());
|
2015-06-14 02:03:13 +01:00
|
|
|
}
|
2015-06-30 20:22:13 +01:00
|
|
|
|
2017-09-14 20:42:43 +01:00
|
|
|
void showColumnsContextMenu(const QPoint& p, QTreeWidget& tree)
|
|
|
|
{
|
|
|
|
QMenu headerMenu(xi18nc("@title:menu", "Columns"));
|
|
|
|
|
|
|
|
QHeaderView* header = tree.header();
|
|
|
|
|
|
|
|
for (qint32 i = 0; i < tree.model()->columnCount(); i++) {
|
|
|
|
const int idx = header->logicalIndex(i);
|
|
|
|
const QString text = tree.model()->headerData(idx, Qt::Horizontal).toString();
|
|
|
|
|
|
|
|
QAction* action = headerMenu.addAction(text);
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(!header->isSectionHidden(idx));
|
|
|
|
action->setData(idx);
|
|
|
|
action->setEnabled(idx > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction* action = headerMenu.exec(tree.header()->mapToGlobal(p));
|
|
|
|
|
|
|
|
if (action != nullptr) {
|
|
|
|
const bool hidden = !action->isChecked();
|
|
|
|
tree.setColumnHidden(action->data().toInt(), hidden);
|
|
|
|
if (!hidden)
|
|
|
|
tree.resizeColumnToContents(action->data().toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
namespace GuiHelpers
|
|
|
|
{
|
2015-06-30 20:22:13 +01:00
|
|
|
|
2015-07-13 15:17:41 +01:00
|
|
|
FileSystem::Type defaultFileSystem()
|
|
|
|
{
|
|
|
|
return static_cast<FileSystem::Type>(Config::defaultFileSystem());
|
|
|
|
}
|
2015-06-30 20:22:13 +01:00
|
|
|
|
2018-04-05 21:54:55 +01:00
|
|
|
std::vector<QColor> fileSystemColorCodesFromSettings()
|
2015-07-17 12:37:08 +01:00
|
|
|
{
|
2018-04-05 21:54:55 +01:00
|
|
|
std::vector<QColor> cc;
|
2018-07-07 14:12:25 +01:00
|
|
|
cc.resize(Config::EnumFileSystem::type::COUNT);
|
2018-04-07 19:05:05 +01:00
|
|
|
for (int i = 0; i < Config::EnumFileSystem::type::COUNT; ++i)
|
2015-07-17 12:37:08 +01:00
|
|
|
{
|
2018-04-07 19:05:05 +01:00
|
|
|
cc[i] = Config::fileSystemColorCode(i);
|
2015-07-17 12:37:08 +01:00
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2015-06-30 20:22:13 +01:00
|
|
|
}
|