diff --git a/src/BookmarkHandler.cpp b/src/BookmarkHandler.cpp index 69aa5a8b..968f2a0a 100644 --- a/src/BookmarkHandler.cpp +++ b/src/BookmarkHandler.cpp @@ -1,192 +1,192 @@ /* This file was part of the KDE libraries Copyright 2002 Carsten Pfeiffer Copyright 2007-2008 Robert Knight library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation, version 2 or ( at your option ), any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // Born as kdelibs/kio/kfile/kfilebookmarkhandler.cpp // Own #include "BookmarkHandler.h" // Qt #include #include #include // KDE #include #include #include #include // Konsole #include "ViewProperties.h" using namespace Konsole; BookmarkHandler::BookmarkHandler(KActionCollection *collection, QMenu *menu, bool toplevel, QObject *parent) : QObject(parent), KBookmarkOwner(), _menu(menu), _bookmarkMenu(nullptr), _file(QString()), _toplevel(toplevel), _activeView(nullptr), _views(QList()) { setObjectName(QStringLiteral("BookmarkHandler")); _file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/bookmarks.xml")); if (_file.isEmpty()) { _file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole"); QDir().mkpath(_file); _file += QStringLiteral("/bookmarks.xml"); } KBookmarkManager *manager = KBookmarkManager::managerForFile(_file, QStringLiteral("konsole")); manager->setUpdate(true); if (toplevel) { _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, collection); } else { _bookmarkMenu = new KBookmarkMenu(manager, this, _menu, nullptr); } } BookmarkHandler::~BookmarkHandler() { delete _bookmarkMenu; } void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) { emit openUrl(bm.url()); } void BookmarkHandler::openFolderinTabs(const KBookmarkGroup &group) { emit openUrls(group.groupUrlList()); } bool BookmarkHandler::enableOption(BookmarkOption option) const { if (option == ShowAddBookmark || option == ShowEditBookmark) { return _toplevel; } else { return KBookmarkOwner::enableOption(option); } } QUrl BookmarkHandler::currentUrl() const { return urlForView(_activeView); } QUrl BookmarkHandler::urlForView(ViewProperties *view) const { if (view != nullptr) { return view->url(); } else { return QUrl(); } } QString BookmarkHandler::currentTitle() const { return titleForView(_activeView); } QString BookmarkHandler::titleForView(ViewProperties *view) const { const QUrl &url = view != nullptr ? view->url() : QUrl(); if (url.isLocalFile()) { QString path = url.path(); path = KShell::tildeExpand(path); - path = QFileInfo(path).baseName(); + path = QFileInfo(path).completeBaseName(); return path; } else if (!url.host().isEmpty()) { if (!url.userName().isEmpty()) { return i18nc("@item:inmenu The user's name and host they are connected to via ssh", "%1 on %2", url.userName(), url.host()); } else { return i18nc("@item:inmenu The host the user is connected to via ssh", "%1", url.host()); } } return url.toDisplayString(); } QString BookmarkHandler::currentIcon() const { return iconForView(_activeView); } QString BookmarkHandler::iconForView(ViewProperties *view) const { if (view != nullptr) { return view->icon().name(); } else { return QString(); } } bool BookmarkHandler::supportsTabs() const { return true; } QList BookmarkHandler::currentBookmarkList() const { QList list; list.reserve(_views.size()); foreach (ViewProperties *view, _views) { list << KBookmarkOwner::FutureBookmark(titleForView(view), urlForView(view), iconForView(view)); } return list; } void BookmarkHandler::setViews(const QList &views) { _views = views; } QList BookmarkHandler::views() const { return _views; } void BookmarkHandler::setActiveView(ViewProperties *view) { _activeView = view; } ViewProperties *BookmarkHandler::activeView() const { return _activeView; } diff --git a/src/ColorSchemeManager.cpp b/src/ColorSchemeManager.cpp index 755805d5..c9d7f666 100644 --- a/src/ColorSchemeManager.cpp +++ b/src/ColorSchemeManager.cpp @@ -1,237 +1,237 @@ /* This source file is part of Konsole, a terminal emulator. Copyright 2007-2008 by Robert Knight 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "ColorSchemeManager.h" #include "konsoledebug.h" // Qt #include #include #include #include // KDE #include using namespace Konsole; ColorSchemeManager::ColorSchemeManager() : _colorSchemes(QHash()), _haveLoadedAll(false) { } ColorSchemeManager::~ColorSchemeManager() { qDeleteAll(_colorSchemes); } Q_GLOBAL_STATIC(ColorSchemeManager, theColorSchemeManager) ColorSchemeManager* ColorSchemeManager::instance() { return theColorSchemeManager; } void ColorSchemeManager::loadAllColorSchemes() { int success = 0; int failed = 0; QStringList nativeColorSchemes = listColorSchemes(); foreach (const QString &colorScheme, nativeColorSchemes) { if (loadColorScheme(colorScheme)) { success++; } else { failed++; } } if (failed > 0) { qCDebug(KonsoleDebug) << "failed to load " << failed << " color schemes."; } _haveLoadedAll = true; } QList ColorSchemeManager::allColorSchemes() { if (!_haveLoadedAll) { loadAllColorSchemes(); } return _colorSchemes.values(); } bool ColorSchemeManager::loadColorScheme(const QString &filePath) { if (!filePath.endsWith(QLatin1String(".colorscheme")) || !QFile::exists(filePath)) { return false; } QFileInfo info(filePath); KConfig config(filePath, KConfig::NoGlobals); auto scheme = new ColorScheme(); - scheme->setName(info.baseName()); + scheme->setName(info.completeBaseName()); scheme->read(config); if (scheme->name().isEmpty()) { qCDebug(KonsoleDebug) << "Color scheme in" << filePath << "does not have a valid name and was not loaded."; delete scheme; return false; } - if (!_colorSchemes.contains(info.baseName())) { + if (!_colorSchemes.contains(info.completeBaseName())) { _colorSchemes.insert(scheme->name(), scheme); } else { //qDebug() << "color scheme with name" << scheme->name() << "has already been" << // "found, ignoring."; delete scheme; } return true; } QStringList ColorSchemeManager::listColorSchemes() { QStringList colorschemes; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"), QStandardPaths::LocateDirectory); colorschemes.reserve(dirs.size()); Q_FOREACH (const QString &dir, dirs) { const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.colorscheme")); Q_FOREACH (const QString &file, fileNames) { colorschemes.append(dir + QLatin1Char('/') + file); } } return colorschemes; } const ColorScheme ColorSchemeManager::_defaultColorScheme; const ColorScheme *ColorSchemeManager::defaultColorScheme() const { return &_defaultColorScheme; } void ColorSchemeManager::addColorScheme(ColorScheme *scheme) { // remove existing colorscheme with the same name if (_colorSchemes.contains(scheme->name())) { delete _colorSchemes[scheme->name()]; _colorSchemes.remove(scheme->name()); } _colorSchemes.insert(scheme->name(), scheme); // save changes to disk const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole/"); QDir().mkpath(dir); const QString path = dir + scheme->name() + QStringLiteral(".colorscheme"); KConfig config(path, KConfig::NoGlobals); scheme->write(config); } bool ColorSchemeManager::deleteColorScheme(const QString &name) { Q_ASSERT(_colorSchemes.contains(name)); // look up the path and delete QString path = findColorSchemePath(name); if (QFile::remove(path)) { delete _colorSchemes[name]; _colorSchemes.remove(name); return true; } else { qCDebug(KonsoleDebug)<<"Failed to remove color scheme -"< 1); } diff --git a/src/KeyboardTranslatorManager.cpp b/src/KeyboardTranslatorManager.cpp index 3c683e1f..15c4bde5 100644 --- a/src/KeyboardTranslatorManager.cpp +++ b/src/KeyboardTranslatorManager.cpp @@ -1,214 +1,214 @@ /* This source file is part of Konsole, a terminal emulator. Copyright 2007-2008 by Robert Knight 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ // Own #include "KeyboardTranslatorManager.h" #include "konsoledebug.h" // Qt #include #include #include #include using namespace Konsole; KeyboardTranslatorManager::KeyboardTranslatorManager() : _haveLoadedAll(false), _fallbackTranslator(nullptr), _translators(QHash()) { _fallbackTranslator = new FallbackKeyboardTranslator(); } KeyboardTranslatorManager::~KeyboardTranslatorManager() { qDeleteAll(_translators); delete _fallbackTranslator; } Q_GLOBAL_STATIC(KeyboardTranslatorManager, theKeyboardTranslatorManager) KeyboardTranslatorManager* KeyboardTranslatorManager::instance() { return theKeyboardTranslatorManager; } void KeyboardTranslatorManager::addTranslator(KeyboardTranslator *translator) { _translators.insert(translator->name(), translator); if (!saveTranslator(translator)) { qCDebug(KonsoleDebug) << "Unable to save translator" << translator->name() << "to disk."; } } bool KeyboardTranslatorManager::deleteTranslator(const QString &name) { Q_ASSERT(_translators.contains(name)); // locate and delete QString path = findTranslatorPath(name); if (QFile::remove(path)) { _translators.remove(name); return true; } else { qCDebug(KonsoleDebug) << "Failed to remove translator - " << path; return false; } } QString KeyboardTranslatorManager::findTranslatorPath(const QString &name) { return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + name + QStringLiteral(".keytab")); } void KeyboardTranslatorManager::findTranslators() { QStringList list; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("konsole"), QStandardPaths::LocateDirectory); list.reserve(dirs.size()); Q_FOREACH (const QString &dir, dirs) { const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.keytab")); Q_FOREACH (const QString &file, fileNames) { list.append(dir + QLatin1Char('/') + file); } } // add the name of each translator to the list and associated // the name with a null pointer to indicate that the translator // has not yet been loaded from disk foreach (const QString &translatorPath, list) { - QString name = QFileInfo(translatorPath).baseName(); + QString name = QFileInfo(translatorPath).completeBaseName(); if (!_translators.contains(name)) { _translators.insert(name, nullptr); } } _haveLoadedAll = true; } const KeyboardTranslator *KeyboardTranslatorManager::findTranslator(const QString &name) { if (name.isEmpty()) { return defaultTranslator(); } if (_translators.contains(name) && _translators[name] != nullptr) { return _translators[name]; } KeyboardTranslator *translator = loadTranslator(name); if (translator != nullptr) { _translators[name] = translator; } else if (!name.isEmpty()) { qCDebug(KonsoleDebug) << "Unable to load translator" << name; } return translator; } bool KeyboardTranslatorManager::saveTranslator(const KeyboardTranslator *translator) { const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/konsole/"); QDir().mkpath(dir); const QString path = dir + translator->name() + QStringLiteral(".keytab"); ////qDebug() << "Saving translator to" << path; QFile destination(path); if (!destination.open(QIODevice::WriteOnly | QIODevice::Text)) { qCDebug(KonsoleDebug) << "Unable to save keyboard translation:" << destination.errorString(); return false; } { KeyboardTranslatorWriter writer(&destination); writer.writeHeader(translator->description()); foreach (const KeyboardTranslator::Entry &entry, translator->entries()) { writer.writeEntry(entry); } } destination.close(); return true; } KeyboardTranslator *KeyboardTranslatorManager::loadTranslator(const QString &name) { const QString &path = findTranslatorPath(name); QFile source(path); if (name.isEmpty() || !source.open(QIODevice::ReadOnly | QIODevice::Text)) { return nullptr; } return loadTranslator(&source, name); } KeyboardTranslator *KeyboardTranslatorManager::loadTranslator(QIODevice *source, const QString &name) { auto translator = new KeyboardTranslator(name); KeyboardTranslatorReader reader(source); translator->setDescription(reader.description()); while (reader.hasNextEntry()) { translator->addEntry(reader.nextEntry()); } source->close(); if (!reader.parseError()) { return translator; } else { delete translator; return nullptr; } } const KeyboardTranslator *KeyboardTranslatorManager::defaultTranslator() { // Try to find the default.keytab file if it exists, otherwise // fall back to the internal hard-coded fallback translator const KeyboardTranslator *translator = findTranslator(QStringLiteral("default")); if (translator == nullptr) { translator = _fallbackTranslator; } return translator; } QStringList KeyboardTranslatorManager::allTranslators() { if (!_haveLoadedAll) { findTranslators(); } return _translators.keys(); }