diff --git a/CMakeLists.txt b/CMakeLists.txt index ce61c8a..2feb2cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,131 +1,131 @@ project(kinfocenter) set(PROJECT_VERSION "5.11.90") cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) -set(QT_MIN_VERSION "5.4.0") +set(QT_MIN_VERSION "5.7.0") -find_package(ECM 1.2.0 REQUIRED NO_MODULE) +set(KF5_MIN_VERSION "5.30") +find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets) -set(KF5_MIN_VERSION "5.30") find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Completion Config ConfigWidgets CoreAddons Crash DBusAddons DocTools I18n IconThemes KCMUtils KIO Service Solid WidgetsAddons XmlGui Declarative Package Solid ) if(${Qt5Gui_OPENGL_IMPLEMENTATION} STREQUAL "GL") find_package(OpenGL) set_package_properties(OpenGL PROPERTIES DESCRIPTION "The OpenGL libraries" URL "http://www.opengl.org" TYPE OPTIONAL ) else() find_package(OpenGLES) set_package_properties(OpenGLES PROPERTIES DESCRIPTION "The OpenGLES libraries" URL "http://www.khronos.org/opengles" TYPE OPTIONAL ) endif() find_package(EGL) set_package_properties(EGL PROPERTIES TYPE OPTIONAL PURPOSE "Required for OpenGL Information Module" ) find_package(KF5Wayland CONFIG) set_package_properties(KF5Wayland PROPERTIES TYPE OPTIONAL ) add_feature_info("KF5Wayland" KF5Wayland_FOUND "Required for Wayland Compositor Information Module") if(NOT APPLE) find_package(X11) set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" URL "http://www.x.org" TYPE OPTIONAL PURPOSE "Required for building the X11 based workspace" ) if(X11_FOUND) set(HAVE_X11 TRUE) endif() else() set(X11_FOUND False) endif() configure_file(config-workspace.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-workspace.h) configure_file(config-X11.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-X11.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions( -DKDE_DEFAULT_DEBUG_AREA=1208 ) remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_KEYWORDS) add_subdirectory( Categories ) add_subdirectory( kcontrol/menus ) add_subdirectory( Modules ) include(ECMOptionalAddSubdirectory) ecm_optional_add_subdirectory( doc ) include_directories( ToolTips ) set( kinfocenter_SRCS infocenter.cpp main.cpp sidepanel.cpp kcmcontainer.cpp kcmtreeitem.cpp kcmcategoryitem.cpp infokcmmodel.cpp infokcmproxymodel.cpp ToolTips/tooltipmanager.cpp ) add_executable( kinfocenter ${kinfocenter_SRCS} ) target_compile_definitions(kinfocenter PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") target_link_libraries( kinfocenter KF5::Completion KF5::ConfigWidgets KF5::CoreAddons KF5::Crash KF5::DBusAddons KF5::I18n KF5::IconThemes KF5::KCMUtils KF5::Service KF5::Solid KF5::WidgetsAddons KF5::XmlGui ) ##install install( TARGETS kinfocenter ${INSTALL_TARGETS_DEFAULT_ARGS} ) install( PROGRAMS org.kde.kinfocenter.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) install( FILES kinfocenterui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kinfocenter ) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/Modules/about-distro/src/Module.cpp b/Modules/about-distro/src/Module.cpp index 1852376..3dea55e 100644 --- a/Modules/about-distro/src/Module.cpp +++ b/Modules/about-distro/src/Module.cpp @@ -1,259 +1,251 @@ /* Copyright (C) 2012-2014 Harald Sitter 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) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. 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 . */ #include "Module.h" #include "ui_Module.h" #include #include -#include #include -#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5,20,0) #include -#endif #include #include #include #include #include #include #include #include #ifdef Q_OS_LINUX #include #elif defined(Q_OS_FREEBSD) #include #include #endif #include #include "OSRelease.h" #include "Version.h" static qlonglong calculateTotalRam() { qlonglong ret = -1; #ifdef Q_OS_LINUX struct sysinfo info; if (sysinfo(&info) == 0) // manpage "sizes are given as multiples of mem_unit bytes" ret = info.totalram * info.mem_unit; #elif defined(Q_OS_FREEBSD) /* Stuff for sysctl */ size_t len; unsigned long memory; len = sizeof(memory); sysctlbyname("hw.physmem", &memory, &len, NULL, 0); ret = memory; #endif return ret; } Module::Module(QWidget *parent, const QVariantList &args) : KCModule(parent, args), ui(new Ui::Module) { KAboutData *aboutData = new KAboutData(QStringLiteral("kcm-about-distro"), i18nc("@title", "About Distribution"), global_s_versionStringFull, QStringLiteral(""), KAboutLicense::LicenseKey::GPL_V3, i18nc("@info:credit", "Copyright 2012-2014 Harald Sitter")); aboutData->addAuthor(i18nc("@info:credit", "Harald Sitter"), i18nc("@info:credit", "Author"), QStringLiteral("apachelogger@kubuntu.org")); setAboutData(aboutData); ui->setupUi(this); QFont font = ui->nameVersionLabel->font(); font.setPixelSize(24); font.setBold(true); ui->nameVersionLabel->setFont(font); QFont fontVariant = ui->variantLabel->font(); fontVariant.setPixelSize(18); fontVariant.setBold(true); ui->variantLabel->setFont(fontVariant); ui->urlLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); // We have no help so remove the button from the buttons. setButtons(buttons() ^ KCModule::Help ^ KCModule::Default ^ KCModule::Apply); // https://bugs.kde.org/show_bug.cgi?id=366158 // When a KCM loads fast enough do a blocking load via the constructor. // Otherwise there is a notciable rendering gap where dummy/no data is // shown. Makes it look bad. load(); } Module::~Module() { delete ui; } void Module::load() { loadSoftware(); loadHardware(); } void Module::save() { } void Module::defaults() { } void Module::loadSoftware() { // NOTE: do not include globals, otherwise kdeglobals could provide values // even though we only explicitly want them from our own config. KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kcm-about-distrorc"), KConfig::NoGlobals); KConfigGroup cg = KConfigGroup(config, "General"); QString logoPath = cg.readEntry("LogoPath", QString()); QPixmap logo; if (logoPath.isEmpty()) { logo = QIcon::fromTheme(QStringLiteral("start-here-kde")).pixmap(128, 128); } else { logo = QPixmap(logoPath); } ui->logoLabel->setPixmap(logo); OSRelease os; // We allow overriding of the OS name for branding purposes. // For example OS Ubuntu may be rebranded as Kubuntu. Also Kubuntu Active // as a product brand is different from Kubuntu. QString distroName = cg.readEntry("Name", os.name); QString versionId = cg.readEntry("Version", os.versionId); ui->nameVersionLabel->setText(QStringLiteral("%1 %2").arg(distroName, versionId)); QString variant = cg.readEntry("Variant", QString()); if (variant.isEmpty()) { ui->variantLabel->hide(); } else { ui->variantLabel->setText(variant); } QString url = cg.readEntry("Website", os.homeUrl); if (url.isEmpty()) { ui->urlLabel->hide(); } else { ui->urlLabel->setText(QStringLiteral("%1").arg(url)); } // Since Plasma version detection isn't based on a library query it can fail // in weird cases; instead of admiting defeat we simply hide everything :P QString plasma = plasmaVersion(); if (plasma.isEmpty()) { ui->plasma->hide(); ui->plasmaLabel->hide(); } else { ui->plasmaLabel->setText(plasma); } ui->qtLabel->setText(qVersion()); -#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5,20,0) ui->frameworksLabel->setText(KCoreAddons::versionString()); -#else - ui->frameworksLabelKey->setVisible(false); - ui->frameworksLabel->setVisible(false); -#endif } void Module::loadHardware() { struct utsname utsName; if(uname(&utsName) != 0) { ui->kernel->hide(); ui->kernelLabel->hide(); } else { ui->kernelLabel->setText(utsName.release); } const int bits = QT_POINTER_SIZE == 8 ? 64 : 32; ui->bitsLabel->setText(i18nc("@label %1 is the CPU bit width (e.g. 32 or 64)", "%1-bit", QString::number(bits))); const QList list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); ui->processor->setText(i18np("Processor:", "Processors:", list.count())); // Format processor string // Group by processor name QMap processorMap; Q_FOREACH(const Solid::Device &device, list) { const QString name = device.product(); auto it = processorMap.find(name); if (it == processorMap.end()) { processorMap.insert(name, 1); } else { ++it.value(); } } // Create a formatted list of grouped processors QStringList names; for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) { const int count = it.value(); QString name = it.key(); name.replace(QStringLiteral("(TM)"), QChar(8482)); name.replace(QStringLiteral("(R)"), QChar(174)); name = name.simplified(); names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); } ui->processorLabel->setText(names.join(QStringLiteral(", "))); if (ui->processorLabel->text().isEmpty()) { ui->processor->setHidden(true); ui->processorLabel->setHidden(true); } const qlonglong totalRam = calculateTotalRam(); ui->memoryLabel->setText(totalRam > 0 ? i18nc("@label %1 is the formatted amount of system memory (e.g. 7,7 GiB)", "%1 of RAM", KFormat().formatByteSize(totalRam)) : i18nc("Unknown amount of RAM", "Unknown")); } QString Module::plasmaVersion() const { const QStringList &filePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("xsessions/plasma.desktop")); if (filePaths.length() < 1) { return QString(); } // Despite the fact that there can be multiple desktop files we simply take // the first one as users usually don't have xsessions/ in their $HOME // data location, so the first match should (usually) be the only one and // reflect the plasma session run. KDesktopFile desktopFile(filePaths.first()); return desktopFile.desktopGroup().readEntry("X-KDE-PluginInfo-Version", QString()); } diff --git a/Modules/devinfo/devicelisting.cpp b/Modules/devinfo/devicelisting.cpp index bb46ff1..ed7b0ef 100644 --- a/Modules/devinfo/devicelisting.cpp +++ b/Modules/devinfo/devicelisting.cpp @@ -1,212 +1,212 @@ /* * devicelisting.cpp * * Copyright (C) 2009 David Hubner * * 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. * */ #include "devicelisting.h" #include DeviceListing::DeviceListing(QWidget *parent, InfoPanel *info, DevInfoPlugin *stat) : QTreeWidget(parent), iPanel(info), status(stat) { // // Check nic changes // nicSig = new NicSignals(); // connect(nicSig,SIGNAL(nicActivatedOrDisconnected()),this,SLOT(networkingChangedSlot())); // // Check if clicked connect(this, &DeviceListing::itemActivated, this, &DeviceListing::itemActivatedSlot); // Check if item is added connect(Solid::DeviceNotifier::instance(),SIGNAL(deviceAdded(QString)),this,SLOT(deviceAddedSlot(QString))); // Check if item is removed connect(Solid::DeviceNotifier::instance(),SIGNAL(deviceRemoved(QString)),this,SLOT(deviceRemovedSlot(QString))); setWhatsThis(i18nc("Device Listing Whats This","Shows all the devices that are currently listed.")); createMenuActions(); setHeaderLabels(QStringList(i18n("Devices"))); populateListing(); } DeviceListing::~DeviceListing() { //delete nicSig; clear(); } void DeviceListing::createMenuActions() { colAct = new QAction(i18n("Collapse All"), this); connect(colAct, &QAction::triggered, this, &DeviceListing::collapseAllDevicesSlot); expAct = new QAction(i18n("Expand All"), this); connect(expAct, &QAction::triggered, this, &DeviceListing::expandAllDevicesSlot); allAct = new QAction(i18n("Show All Devices"), this); connect(allAct, &QAction::triggered, this, &DeviceListing::showAllDevicesSlot); relAct = new QAction(i18n("Show Relevant Devices"), this); connect(relAct, &QAction::triggered, this, &DeviceListing::showRelevantDevicesSlot); } void DeviceListing::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); menu.addAction(colAct); menu.addAction(expAct); menu.addAction(allAct); menu.addAction(relAct); menu.exec(event->globalPos()); } QTreeWidgetItem *DeviceListing::createListItems(const Solid::DeviceInterface::Type &type) { switch(type) { case Solid::DeviceInterface::Processor: return new SolProcessorDevice(type); case Solid::DeviceInterface::StorageDrive: return new SolStorageDevice(type); case Solid::DeviceInterface::Camera: return new SolCameraDevice(type); case Solid::DeviceInterface::PortableMediaPlayer: return new SolMediaPlayerDevice(type); case Solid::DeviceInterface::Battery: return new SolBatteryDevice(type); default: return new SolDevice(type,i18nc("unknown device type", "Unknown")); } } void DeviceListing::populateListing(const show showStatus) { const Solid::DeviceInterface::Type needHardware[] = { Solid::DeviceInterface::Processor, Solid::DeviceInterface::StorageDrive, Solid::DeviceInterface::Battery, Solid::DeviceInterface::PortableMediaPlayer, Solid::DeviceInterface::Camera }; clear(); for(unsigned int i=0;i<(sizeof(needHardware)/sizeof(Solid::DeviceInterface::Type));i++) { QTreeWidgetItem *tmpDevice = createListItems(needHardware[i]); deviceMap[needHardware[i]] = static_cast(tmpDevice); if((tmpDevice->childCount() > 0) || (showStatus==ALL)) { addTopLevelItem(tmpDevice); } } } void DeviceListing::itemActivatedSlot(QTreeWidgetItem *listItemIn ,const int columnIn) { Q_UNUSED(columnIn); SolDevice *listItem = static_cast(listItemIn); if(listItem->isDeviceSet()) { iPanel->setTopInfo(listItem->deviceIcon(),listItem->device()); QVListLayout *bottomLay = listItem->infoPanelLayout(); if(!bottomLay) return; iPanel->setBottomInfo(bottomLay); } else { status->updateStatus(i18nc("no device UDI", "None")); } } void DeviceListing::deviceAddedSlot(const QString udi) { SolidHelper *solhelp = new SolidHelper(); const QList list = Solid::Device::allDevices(); foreach(const Solid::Device &dev, list) { if(dev.udi() == udi) { Solid::DeviceInterface::Type deviceType = solhelp->deviceType(&dev); QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this,dev.parentUdi()); // Incase of bad index if(deviceMap[deviceType] == NULL) { QTreeWidgetItem *topItem = topLevelItem(0); if(topItem == 0) { delete solhelp; return; } deviceMap[deviceType] = static_cast(topItem); } switch(deviceType) { case Solid::DeviceInterface::Processor: new SolProcessorDevice(deviceMap[deviceType],dev); break; case Solid::DeviceInterface::Camera: new SolCameraDevice(deviceMap[deviceType],dev); break; case Solid::DeviceInterface::PortableMediaPlayer: new SolMediaPlayerDevice(deviceMap[deviceType],dev); break; case Solid::DeviceInterface::Battery: new SolBatteryDevice(deviceMap[deviceType],dev); break; case Solid::DeviceInterface::StorageDrive: new SolStorageDevice(deviceMap[deviceType],dev,SolStorageDevice::NOCHILDREN); break; case Solid::DeviceInterface::StorageVolume: if(parent == NULL) break; new SolVolumeDevice(parent,dev); break; default: break; } } } delete solhelp; } void DeviceListing::deviceRemovedSlot(const QString udi) { const QTreeWidgetItem *item = getTreeWidgetItemFromUdi(this,udi); - if(item == NULL) return; + if(item == nullptr) return; delete item; } void DeviceListing::collapseAllDevicesSlot() { collapseAll(); } void DeviceListing::expandAllDevicesSlot() { expandAll(); } void DeviceListing::showAllDevicesSlot() { populateListing(ALL); } void DeviceListing::showRelevantDevicesSlot() { populateListing(RELEVANT); } diff --git a/Modules/devinfo/infopanel.cpp b/Modules/devinfo/infopanel.cpp index a37f786..0ad152e 100644 --- a/Modules/devinfo/infopanel.cpp +++ b/Modules/devinfo/infopanel.cpp @@ -1,143 +1,143 @@ /* * infopanel.cpp * * Copyright (C) 2009 David Hubner * * 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. * */ #include "infopanel.h" InfoPanel::InfoPanel(QWidget *parent, DevInfoPlugin *stat) : QGroupBox(i18n("Device Information"),parent), status(stat) { setMinimumWidth(300); setInfoPanelLayout(); setDefaultText(); adjustSize(); setWhatsThis(i18nc("Info Panel Whats This","Shows information about the currently selected device.")); } InfoPanel::~InfoPanel() { delete top; delete bottom; } void InfoPanel::setInfoPanelLayout() { vLayout = setAlignedLayout(this); setLayout(vLayout); setTopWidgetLayout(true); setBottomWidgetLayout(new QVListLayout(),true); } void InfoPanel::setDefaultText() { QLabel *defaultText = new QLabel(); QFont font; font.setBold(true); defaultText->setAlignment(Qt::AlignHCenter); defaultText->setFont(font); defaultText->setText(i18n("\nSolid Based Device Viewer Module")); QVBoxLayout *lay = static_cast(top->layout()); lay->addWidget(setDevicesIcon(QIcon::fromTheme(QStringLiteral("kde"))),0,Qt::AlignHCenter); lay->addWidget(defaultText,0,Qt::AlignHCenter); } -void InfoPanel::setTopWidgetLayout(const bool &isInit) +void InfoPanel::setTopWidgetLayout(bool isInit) { if(!isInit) delete top; top = new QWidget(this); vLayout->addWidget(top); top->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); top->setLayout(setAlignedLayout(top)); } -QVBoxLayout *InfoPanel::setAlignedLayout(QWidget *parent, const int &spacingHeight) +QVBoxLayout *InfoPanel::setAlignedLayout(QWidget *parent, int spacingHeight) { QVBoxLayout *lay = new QVBoxLayout(parent); lay->insertSpacing(0,spacingHeight); lay->setAlignment(Qt::AlignTop); return lay; } -void InfoPanel::setBottomWidgetLayout(QVListLayout *lay, const bool &isInit) +void InfoPanel::setBottomWidgetLayout(QVListLayout *lay, bool isInit) { if(!isInit) delete bottom; bottom = new QWidget(this); vLayout->addWidget(bottom); bottom->setLayout(lay); } void InfoPanel::setBottomInfo(QVListLayout *lay) { lay->setAlignment(Qt::AlignTop); lay->insertSpacing(0,10); setBottomWidgetLayout(lay); } QLabel *InfoPanel::setDevicesIcon(const QIcon &deviceIcon) { QLabel *iconLabel = new QLabel(); iconLabel->setPixmap(deviceIcon.pixmap(QSize(70,50))); return iconLabel; } void InfoPanel::setTopInfo(const QIcon &deviceIcon, Solid::Device *device) { QList labels; setTopWidgetLayout(); QVListLayout *tLayout = static_cast(top->layout()); tLayout->addWidget(setDevicesIcon(deviceIcon),0,Qt::AlignHCenter); labels << i18n("Product: ") << device->product() << i18n("Vendor: ") << friendlyString(device->vendor()); status->updateStatus(device->udi()); tLayout->applyQListToLayout(labels); } QString InfoPanel::friendlyString(const QString &input, const QString &blankName) { if(input.isEmpty()) return QString(blankName); if(input.length() >= 40) return input.left(39); return input; } -QString InfoPanel::convertTf(const bool &b) +QString InfoPanel::convertTf(bool b) { if(b) return i18n("Yes"); return i18n("No"); } diff --git a/Modules/devinfo/infopanel.h b/Modules/devinfo/infopanel.h index 9629785..8a176bd 100644 --- a/Modules/devinfo/infopanel.h +++ b/Modules/devinfo/infopanel.h @@ -1,76 +1,76 @@ /* * infopanel.h * * Copyright (C) 2009 David Hubner * * 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. * */ #ifndef INFOPANEL #define INFOPANEL // QT #include #include #include //Solid #include #include #include #include //KDE #include //Local #include "qvlistlayout.h" #include "devinfo.h" class DevInfoPlugin; class InfoPanel : public QGroupBox { Q_OBJECT public: InfoPanel(QWidget *, DevInfoPlugin *); ~InfoPanel(); void setTopInfo(const QIcon &, Solid::Device *); void setBottomInfo(QVListLayout *lay); static QString friendlyString(const QString &, const QString & = i18nc("name of something is not known", "Unknown")); - static QString convertTf(const bool &); + static QString convertTf(bool ); private: - void setTopWidgetLayout(const bool & = false); - void setBottomWidgetLayout(QVListLayout *, const bool & = false); + void setTopWidgetLayout(bool = false); + void setBottomWidgetLayout(QVListLayout *, bool = false); void setInfoPanelLayout(); void removeItems(QWidget *); void setDefaultText(); QLabel *setDevicesIcon(const QIcon &); - QVBoxLayout *setAlignedLayout(QWidget *parent, const int & = 0); + QVBoxLayout *setAlignedLayout(QWidget *parent, int = 0); QWidget *top; QWidget *bottom; QVBoxLayout *vLayout; Solid::Device *dev; DevInfoPlugin *status; }; #endif //INFOPANEL diff --git a/Modules/energy/statisticsprovider.cpp b/Modules/energy/statisticsprovider.cpp index 3721328..9051818 100644 --- a/Modules/energy/statisticsprovider.cpp +++ b/Modules/energy/statisticsprovider.cpp @@ -1,202 +1,203 @@ /* * * Copyright (C) 2015 David Edmundson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "statisticsprovider.h" #include #include #include #include #include #include // qDBusRegisterMetaType #include const QDBusArgument &operator<<(QDBusArgument &argument, const HistoryReply &data) { argument.beginStructure(); argument << data.time << data.value << data.charging; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &arg, HistoryReply &attrs) { arg.beginStructure(); arg >> attrs.time >> attrs.value >> attrs.charging; arg.endStructure(); return arg; } StatisticsProvider::StatisticsProvider(QObject *parent) : QObject(parent) { m_type = StatisticsProvider::ChargeType; m_duration = 120; qDBusRegisterMetaType(); qDBusRegisterMetaType >(); } void StatisticsProvider::setDevice(const QString &device) { if (device == m_device) { return; } m_device = device; Q_EMIT deviceChanged(); load(); } void StatisticsProvider::setDuration(uint duration) { if (duration == m_duration) { return; } m_duration = duration; Q_EMIT durationChanged(); load(); } void StatisticsProvider::setType(StatisticsProvider::HistoryType type) { if (m_type == type) { return; } m_type = type; Q_EMIT typeChanged(); load(); } void StatisticsProvider::classBegin() { } void StatisticsProvider::componentComplete() { m_isComplete = true; load(); } QVariantList StatisticsProvider::asPoints() const { QVariantList points; + points.reserve(m_values.count()); foreach (const HistoryReply &h, m_values) { points.append(QPointF(h.time, h.value)); } if (!points.isEmpty()) { points.takeLast(); } return points; } int StatisticsProvider::count() const { return m_values.count(); } int StatisticsProvider::firstDataPointTime() const { if (m_values.isEmpty()) { return 0; } return m_values.first().time; } int StatisticsProvider::lastDataPointTime() const { if (m_values.isEmpty()) { return 0; } return m_values.last().time; } int StatisticsProvider::largestValue() const { if (m_values.isEmpty()) { return 0; } int max = 0; // TODO std::max or something? for (auto it = m_values.constBegin(); it != m_values.constEnd(); ++it) { if ((*it).value > max) { max = (*it).value; } } return max; } void StatisticsProvider::refresh() { load(); } void StatisticsProvider::load() { if (!m_isComplete || m_device.isEmpty()) { return; } auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UPower"), m_device, QStringLiteral("org.freedesktop.UPower.Device"), QStringLiteral("GetHistory")); if (m_type == RateType) { msg << QLatin1String("rate"); } else { // m_type must = ChargeType msg << QLatin1String("charge"); } uint resolution = 100; msg << m_duration << resolution; QDBusPendingReply> reply = QDBusConnection::systemBus().asyncCall(msg); auto *watcher = new QDBusPendingCallWatcher(reply, this); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { QDBusPendingReply> reply = *watcher; watcher->deleteLater(); m_values.clear(); if (reply.isError()) { qWarning() << "Failed to get device history from UPower" << reply.error().message(); return; } foreach (const HistoryReply &r, reply.value()) { if (r.value > 0) { //we get back some values which contain no value, possibly to indicate if charging changes, ignore them m_values.prepend(r); } } Q_EMIT dataChanged(); }); } #include "statisticsprovider.moc" diff --git a/Modules/usbview/usbdevices.cpp b/Modules/usbview/usbdevices.cpp index 45dfb7f..318dd1b 100644 --- a/Modules/usbview/usbdevices.cpp +++ b/Modules/usbview/usbdevices.cpp @@ -1,435 +1,435 @@ /*************************************************************************** * Copyright (C) 2001 by Matthias Hoelzer-Kluepfel * * * * 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. * * * ***************************************************************************/ #include "usbdevices.h" #include #include #include #include #include #include #include #include #include #include #include "usbdb.h" #include #if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include #include #endif QList USBDevice::_devices; USBDB *USBDevice::_db; USBDevice::USBDevice() : _bus(0), _level(0), _parent(0), _port(0), _count(0), _device(0), _channels(0), _power(0), _speed(0.0), _bwTotal(0), _bwUsed(0), _bwPercent(0), _bwIntr(0), _bwIso(0), _hasBW(false), _verMajor(0), _verMinor(0), _class(0), _sub(0), _prot(0), _maxPacketSize(0), _configs(0), _vendorID(0), _prodID(0), _revMajor(0), _revMinor(0) { _devices.append(this); if (!_db) _db = new USBDB; } USBDevice::~USBDevice() { } -static QString catFile(QString fname) { +static QString catFile(const QString &fname) { char buffer[256]; QString result; int fd =:: open(QFile::encodeName(fname), O_RDONLY); if (fd<0) return QString(); if (fd >= 0) { ssize_t count; while ((count = ::read(fd, buffer, 256)) > 0) result.append(QString(buffer).leftRef(count)); ::close(fd); } return result.trimmed(); } void USBDevice::parseSysDir(int bus, int parent, int level, const QString& dname) { _level = level; _parent = parent; _manufacturer = catFile(dname + "/manufacturer"); _product = catFile(dname + "/product"); _bus = bus; _device = catFile(dname + "/devnum").toUInt(); if (_device == 1) _product += QStringLiteral(" (%1)").arg(_bus); _vendorID = catFile(dname + "/idVendor").toUInt(0, 16); _prodID = catFile(dname + "/idProduct").toUInt(0, 16); _class = catFile(dname + "/bDeviceClass").toUInt(0, 16); _sub = catFile(dname + "/bDeviceSubClass").toUInt(0, 16); _maxPacketSize = catFile(dname + "/bMaxPacketSize0").toUInt(); _speed = catFile(dname + "/speed").toDouble(); _serial = catFile(dname + "/serial"); _channels = catFile(dname + "/maxchild").toUInt(); double version = catFile(dname + "/version").toDouble(); _verMajor = int(version); _verMinor = int(10*(version - floor(version))); QDir dir(dname); dir.setNameFilters(QStringList() << QStringLiteral("%1-*").arg(bus)); dir.setFilter(QDir::Dirs); const QStringList list = dir.entryList(); for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) { if ((*it).contains(':')) continue; USBDevice* dev = new USBDevice(); dev->parseSysDir(bus, ++level, _device, dname + '/' + *it); } } void USBDevice::parseLine(const QString& line) { if (line.startsWith(QLatin1String("T:"))) sscanf(line.toLocal8Bit().data(), "T: Bus=%2d Lev=%2d Prnt=%2d Port=%d Cnt=%2d Dev#=%3d Spd=%3f MxCh=%2d", &_bus, &_level, &_parent, &_port, &_count, &_device, &_speed, &_channels); else if (line.startsWith(QLatin1String("S: Manufacturer"))) _manufacturer = line.mid(17); else if (line.startsWith(QLatin1String("S: Product"))) { _product = line.mid(12); /* add bus number to root devices */ if (_device==1) _product += QStringLiteral(" (%1)").arg(_bus); } else if (line.startsWith(QLatin1String("S: SerialNumber"))) _serial = line.mid(17); else if (line.startsWith(QLatin1String("B:"))) { sscanf(line.toLocal8Bit().data(), "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d", &_bwUsed, &_bwTotal, &_bwPercent, &_bwIntr, &_bwIso); _hasBW = true; } else if (line.startsWith(QLatin1String("D:"))) { char buffer[11]; sscanf(line.toLocal8Bit().data(), "D: Ver=%x.%x Cls=%x(%10s) Sub=%x Prot=%x MxPS=%u #Cfgs=%u", &_verMajor, &_verMinor, &_class, buffer, &_sub, &_prot, &_maxPacketSize, &_configs); _className = buffer; } else if (line.startsWith(QLatin1String("P:"))) sscanf(line.toLocal8Bit().data(), "P: Vendor=%x ProdID=%x Rev=%x.%x", &_vendorID, &_prodID, &_revMajor, &_revMinor); } USBDevice* USBDevice::find(int bus, int device) { foreach(USBDevice* usbDevice, _devices) { if (usbDevice->bus() == bus && usbDevice->device() == device) return usbDevice; } return NULL; } QString USBDevice::product() { if (!_product.isEmpty()) return _product; QString pname = _db->device(_vendorID, _prodID); if (!pname.isEmpty()) return pname; return i18n("Unknown"); } QString USBDevice::dump() { QString r; r = "

" + product() + "


"; if (!_manufacturer.isEmpty()) r += i18n("Manufacturer: ") + _manufacturer + "
"; if (!_serial.isEmpty()) r += i18n("Serial #: ") + _serial + "
"; r += QLatin1String("
"); QString c = QStringLiteral("").arg(_class); QString cname = _db->cls(_class); if (!cname.isEmpty()) c += ""; r += i18n("%1", c); QString sc = QStringLiteral("").arg(_sub); QString scname = _db->subclass(_class, _sub); if (!scname.isEmpty()) sc += ""; r += i18n("%1", sc); QString pr = QStringLiteral("").arg(_prot); QString prname = _db->protocol(_class, _sub, _prot); if (!prname.isEmpty()) pr += ""; r += i18n("%1", pr); #if !(defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) r += ki18n("") .subs(_verMajor,0,16).subs(_verMinor,2,16,QChar::fromLatin1('0')) .toString(); #endif r += QLatin1String(""); QString v = QString::number(_vendorID, 16); QString name = _db->vendor(_vendorID); if (!name.isEmpty()) v += ""; r += i18n("", v); QString p = QString::number(_prodID, 16); QString pname = _db->device(_vendorID, _prodID); if (!pname.isEmpty()) p += ""; r += i18n("", p); r += ki18n("") .subs(_revMajor,0,16).subs(_revMinor,2,16,QChar::fromLatin1('0')) .toString(); r += QLatin1String(""); r += i18n("", _speed); r += i18n("", _channels); #if (defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) && !defined(DISABLE_USBDEVICES_FREEBSD) if ( _power ) r += i18n("", _power); else r += i18n(""); r += i18n("", _devnodes.at(0)); if ( _devnodes.count() > 1 ) { QStringList::const_iterator it = _devnodes.constBegin(); ++it; for (; it != _devnodes.constEnd(); ++it ) r += ""; } #else r += i18n("", _maxPacketSize); #endif r += QLatin1String(""); if (_hasBW) { r += i18n("", _bwUsed, _bwTotal, _bwPercent); r += i18n("", _bwIntr); r += i18n("", _bwIso); r += QLatin1String(""); } r += QLatin1String("
%1(" + i18n(cname.toLatin1()) +")
Class
%1(" + i18n(scname.toLatin1()) +")
Subclass
%1(" + prname +")
Protocol
USB Version%1.%2
(" + name +")
Vendor ID0x%1
(" + pname +")
Product ID0x%1
Revision%1.%2
Speed%1 Mbit/s
Channels%1
Power Consumption%1 mA
Power Consumptionself powered
Attached Devicenodes%1
" + *it + "
Max. Packet Size%1
Bandwidth%1 of %2 (%3%)
Intr. requests%1
Isochr. requests%1
"); return r; } #if !(defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) bool USBDevice::parse(const QString &fname) { _devices.clear(); QString result; // read in the complete file // // Note: we can't use a QTextStream, as the files in /proc // are pseudo files with zero length char buffer[256]; int fd =:: open(QFile::encodeName(fname), O_RDONLY); if (fd<0) return false; if (fd >= 0) { ssize_t count; while ((count = ::read(fd, buffer, 256)) > 0) result.append(QString(buffer).leftRef(count)); ::close(fd); } // read in the device infos USBDevice *device = 0; int start=0, end; result.replace(QRegExp(QStringLiteral("^\n")),QLatin1String("")); while ((end = result.indexOf('\n', start)) > 0) { QString line = result.mid(start, end-start); if (line.startsWith(QLatin1String("T:"))) device = new USBDevice(); if (device) device->parseLine(line); start = end+1; } return true; } bool USBDevice::parseSys(const QString &dname) { QDir d(dname); d.setNameFilters(QStringList() << QStringLiteral("usb*")); const QStringList list = d.entryList(); for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) { USBDevice* device = new USBDevice(); int bus = 0; QRegExp bus_reg(QStringLiteral("[a-z]*([0-9]+)")); if (bus_reg.indexIn(*it) != -1) bus = bus_reg.cap(1).toInt(); device->parseSysDir(bus, 0, 0, d.absolutePath() + '/' + *it); } return d.count(); } #else // Unused by *BSD bool USBDevice::parseSys(const QString &fname) { Q_UNUSED(fname) return true; } # if defined(DISABLE_USBDEVICES_FREEBSD) /* * FIXME: The USB subsystem has changed a lot in FreeBSD 8.0 * Support for it must be written. */ bool USBDevice::parse(const QString &fname) { Q_UNUSED(fname) return true; } # else /* * FreeBSD support by Markus Brueffer * * Basic idea and some code fragments were taken from FreeBSD's usbdevs(8), * originally developed for NetBSD, so this code should work with no or * only little modification on NetBSD. */ void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent) { // determine data for this device _level = level; _parent = parent; _bus = di.udi_bus; _device = di.udi_addr; _product = QLatin1String(di.udi_product); if ( _device == 1 ) _product += ' ' + QString::number( _bus ); _manufacturer = QLatin1String(di.udi_vendor); _prodID = di.udi_productNo; _vendorID = di.udi_vendorNo; _class = di.udi_class; _sub = di.udi_subclass; _prot = di.udi_protocol; _power = di.udi_power; _channels = di.udi_nports; // determine the speed #if defined(__DragonFly__) || (defined(Q_OS_FREEBSD) && __FreeBSD_version > 490102) || defined(Q_OS_NETBSD) switch (di.udi_speed) { case USB_SPEED_LOW: _speed = 1.5; break; case USB_SPEED_FULL: _speed = 12.0; break; case USB_SPEED_HIGH: _speed = 480.0; break; } #else _speed = di.udi_lowspeed ? 1.5 : 12.0; #endif // Get all attached devicenodes for ( int i = 0; i < USB_MAX_DEVNAMES; ++i ) if ( di.udi_devnames[i][0] ) _devnodes << di.udi_devnames[i]; // For compatibility, split the revision number sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor ); // Cycle through the attached devices if there are any for ( int p = 0; p < di.udi_nports; ++p ) { // Get data for device struct usb_device_info di2; di2.udi_addr = di.udi_ports[p]; if ( di2.udi_addr >= USB_MAX_DEVICES ) continue; if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 ) continue; // Only add the device if we didn't detect it, yet if (!find( di2.udi_bus, di2.udi_addr ) ) { USBDevice *device = new USBDevice(); device->collectData( fd, level + 1, di2, di.udi_addr ); } } } bool USBDevice::parse(const QString &fname) { Q_UNUSED(fname) static bool showErrorMessage = true; bool error = false; _devices.clear(); QFile controller("/dev/usb0"); int i = 1; while ( controller.exists() ) { // If the devicenode exists, continue with further inspection if ( controller.open(QIODevice::ReadOnly) ) { for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) { struct usb_device_info di; di.udi_addr = addr; if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 ) { if (!find( di.udi_bus, di.udi_addr ) ) { USBDevice *device = new USBDevice(); device->collectData( controller.handle(), 0, di, 0); } } } controller.close(); #ifndef Q_OS_NETBSD } else { error = true; #endif } controller.setFileName( QString::fromLocal8Bit("/dev/usb%1").arg(i++) ); } if ( showErrorMessage && error ) { showErrorMessage = false; KMessageBox::error( 0, i18n("Could not open one or more USB controller. Make sure, you have read access to all USB controllers that should be listed here.")); } return true; } # endif // defined(DISABLE_USBDEVICES_FREEBSD) #endif // !(defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)) diff --git a/ToolTips/tooltipmanager.cpp b/ToolTips/tooltipmanager.cpp index 6827d27..4264973 100644 --- a/ToolTips/tooltipmanager.cpp +++ b/ToolTips/tooltipmanager.cpp @@ -1,194 +1,188 @@ /******************************************************************************* * Copyright (C) 2008 by Konstantin Heil * * * * 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 * *******************************************************************************/ #include "tooltipmanager.h" #include "kcmtreeitem.h" #include "sidepanel.h" #include #include #include #include #include #include #include #include #include #include class ToolTipManager::Private { public: - Private() : - view(0), - timer(0), - delay(50) - { } - - KToolTipWidget *tooltip; - QAbstractItemView* view; - QTimer* timer; + KToolTipWidget *tooltip = nullptr; + QAbstractItemView* view = nullptr; + QTimer* timer = nullptr; QModelIndex item; QRect itemRect; - int delay; + int delay = 50; }; ToolTipManager::ToolTipManager(QAbstractItemView* parent) : QObject(parent) , d(new ToolTipManager::Private) { d->view = parent; d->tooltip = new KToolTipWidget(d->view); d->tooltip->setHideDelay(0); connect(parent, &QAbstractItemView::viewportEntered, this, &ToolTipManager::hideToolTip); connect(parent, &QAbstractItemView::entered, this, &ToolTipManager::requestToolTip); d->timer = new QTimer(this); d->timer->setSingleShot(true); connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); // When the mousewheel is used, the items don't get a hovered indication // (Qt-issue #200665). To assure that the tooltip still gets hidden, // the scrollbars are observed. connect(parent->horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip); connect(parent->verticalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip); d->view->viewport()->installEventFilter(this); } ToolTipManager::~ToolTipManager() { delete d; } bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { if ( watched == d->view->viewport() ) { switch ( event->type() ) { case QEvent::Leave: case QEvent::MouseButtonPress: hideToolTip(); break; case QEvent::ToolTip: return true; default: break; } } return QObject::eventFilter(watched, event); } void ToolTipManager::requestToolTip(const QModelIndex& index) { // only request a tooltip for the name column and when no selection or // drag & drop operation is done (indicated by the left mouse button) if ( !(QApplication::mouseButtons() & Qt::LeftButton) ) { d->tooltip->hide(); d->itemRect = d->view->visualRect(index); const QPoint pos = d->view->viewport()->mapToGlobal(d->itemRect.topLeft()); d->itemRect.moveTo(pos); d->item = index; d->timer->start(d->delay); } else { hideToolTip(); } } void ToolTipManager::hideToolTip() { d->timer->stop(); d->tooltip->hideLater(); } void ToolTipManager::prepareToolTip() { showToolTip( d->item ); } void ToolTipManager::showToolTip( const QModelIndex& menuItem ) { if (QApplication::mouseButtons() & Qt::LeftButton) { return; } QWidget * tip = createTipContent( menuItem ); connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater); d->tooltip->showBelow(d->itemRect, tip, d->view->nativeParentWidget()->windowHandle()); } QWidget * ToolTipManager::createTipContent( const QModelIndex& item ) { QWidget * tipContent = new QWidget(); QGridLayout* tipLayout = new QGridLayout(); QLayout * primaryLine = generateToolTipLine( item, tipContent, QSize(32,32), true ); tipLayout->addLayout( primaryLine, 0, 0 ); for ( int done = 0; d->view->model()->rowCount( item ) > done; done = 1 + done ) { QModelIndex childItem = d->view->model()->index( done, 0, item ); QLayout * subLine = generateToolTipLine( childItem, tipContent, QSize(24,24), false ); tipLayout->addLayout( subLine, done + 2, 0 ); } tipLayout->setVerticalSpacing( 0 ); tipContent->setLayout( tipLayout ); if( d->view->model()->rowCount( item ) > 0 ) { QFrame * separatorLine = new QFrame( tipContent ); separatorLine->setFrameStyle( QFrame::HLine ); tipLayout->addWidget( separatorLine, 1, 0 ); } return tipContent; } QLayout * ToolTipManager::generateToolTipLine( const QModelIndex & item, QWidget * toolTip, const QSize& iconSize, bool comment ) { SidePanel *sidePanel = static_cast(d->view); KcmTreeItem *menuItem = static_cast( sidePanel->mapToProxySource(item).internalPointer() ); QString text = menuItem->data(); if ( comment ) { text = QStringLiteral( "%1" ).arg( menuItem->data() ); } QLabel * textLabel = new QLabel( toolTip ); textLabel->setForegroundRole(QPalette::ToolTipText); textLabel->setText( text ); // Get icon QIcon icon( menuItem->icon() ); QLabel * iconLabel = new QLabel( toolTip ); iconLabel->setPixmap( icon.pixmap(iconSize) ); iconLabel->setMaximumSize( iconSize ); // Generate layout QHBoxLayout * layout = new QHBoxLayout(); layout->addWidget( iconLabel ); layout->addWidget( textLabel ); return layout; } diff --git a/infocenter.cpp b/infocenter.cpp index 125e952..62a1e1c 100644 --- a/infocenter.cpp +++ b/infocenter.cpp @@ -1,245 +1,245 @@ /* * infocenter.cpp * * Copyright (C) 2010 David Hubner * * 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. * */ //Local #include "infocenter.h" //KDE #include #include #include #include #include #include #include #include #include #include #include //QT #include #include #include #include #include #include #include #include KInfoCenter::KInfoCenter() : KXmlGuiWindow( 0, Qt::WindowContextHelpButtonHint ) { setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo"))); setWindowTitle(i18nc("Main window title", "KInfocenter")); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_cWidget = new QWidget(this); setCentralWidget(m_cWidget); QVBoxLayout *cLayout = new QVBoxLayout(m_cWidget); Q_UNUSED(cLayout); cLayout->setSpacing(0); cLayout->setContentsMargins(0, 0, 0, 0); createMainFrame(); createToolBar(); //TreeWidget connect(m_sideMenu,SIGNAL(clicked(const KcmTreeItem*)),this,SLOT(itemClickedSlot(const KcmTreeItem*))); //SearchBox connect(m_searchText, &QLineEdit::textChanged, m_sideMenu, &SidePanel::filterSideMenuSlot); connect(m_searchAction, SIGNAL(triggered()),m_searchText,SLOT(setFocus())); //Buttons connect(m_moduleHelpAction, &QAction::triggered,this,&KInfoCenter::helpClickedSlot); //Menu connect(m_aboutKcm, &QAction::triggered, this, &KInfoCenter::aboutKcmSlot); //Startup m_searchText->completionObject()->setItems(m_sideMenu->allChildKeywords()); m_sideMenu->setFocus(Qt::OtherFocusReason); m_sideMenu->changeToFirstValidItem(); m_toolTips = new ToolTipManager(m_sideMenu); setupGUI(QSize(640,480), ToolBar | Keys | Save | Create, QStringLiteral("kinfocenterui.rc")); m_helpAction->setMenu( dynamic_cast( factory()->container(QStringLiteral("help"), this) ) ); menuBar()->hide(); QAction *aboutApp = actionCollection()->action(QStringLiteral("help_about_app")); aboutApp->setIcon(QIcon::fromTheme(QStringLiteral("hwinfo"))); } KInfoCenter::~KInfoCenter() { delete m_toolTips; //TreeWidget disconnect(m_sideMenu,SIGNAL(clicked(const KcmTreeItem*)),this,SLOT(itemClickedSlot(const KcmTreeItem*))); //SearchBox disconnect(m_searchText, &QLineEdit::textChanged, m_sideMenu, &SidePanel::filterSideMenuSlot); disconnect(m_searchAction, SIGNAL(triggered()),m_searchText, SLOT(setFocus())); //Buttons - disconnect(m_moduleHelpAction, &QAction::triggered,this,&KInfoCenter::helpClickedSlot); + disconnect(m_moduleHelpAction, &QAction::triggered, this, &KInfoCenter::helpClickedSlot); //Menu disconnect(m_aboutKcm, &QAction::triggered, this, &KInfoCenter::aboutKcmSlot); } bool KInfoCenter::eventFilter(QObject *watched, QEvent *event) { if (watched == m_sideMenu && event->type() == QEvent::Move) { m_contain->setKcmTopEdge(m_sideMenu->y()); } return false; } void KInfoCenter::createToolBar() { KStandardAction::quit(this, SLOT(close()), actionCollection()); KStandardAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection()); toolBar()->setMovable(false); m_aboutKcm = actionCollection()->addAction(QStringLiteral("help_about_module")); m_aboutKcm->setText(i18nc("Information about current module located in about menu","About Current Information Module")); m_aboutKcm->setIcon(QIcon::fromTheme(QStringLiteral("help-about"))); m_aboutKcm->setEnabled(false); m_moduleHelpAction = new QAction(this); m_moduleHelpAction->setText(i18nc("Module help button label", "Module Help")); m_moduleHelpAction->setIcon(QIcon::fromTheme(QStringLiteral("help-contextual"))); m_helpAction = new KActionMenu( QIcon::fromTheme(QStringLiteral("help-contents")), i18nc("Help button label","Help"), this ); m_helpAction->setDelayed( false ); actionCollection()->addAction(QStringLiteral("helpModule"), m_moduleHelpAction); actionCollection()->addAction(QStringLiteral("helpMenu"), m_helpAction); } void KInfoCenter::createMainFrame() { QWidget *mainDisplay = new QWidget(); mainDisplay->setContentsMargins(0,0,0,0); QHBoxLayout *mainLayout = new QHBoxLayout(mainDisplay); m_splitter = new QSplitter(m_cWidget); m_splitter->setContentsMargins(0, 0, 0, 0); m_splitter->setHandleWidth(5); mainLayout->addWidget(m_splitter); createMenuFrame(); m_contain = new KcmContainer(m_splitter); m_splitter->addWidget(m_contain); m_splitter->setStretchFactor(0, 0); m_splitter->setStretchFactor(1, 1); m_cWidget->layout()->addWidget(mainDisplay); } void KInfoCenter::createMenuFrame() { QWidget *sideFrame = new QWidget(m_splitter); sideFrame->setContentsMargins(0,0,0,0); QVBoxLayout *menuLayout = new QVBoxLayout(sideFrame); menuLayout->setContentsMargins(0, 0, 0, 0); m_searchText = new KLineEdit(sideFrame); m_searchText->setClearButtonEnabled(true); m_searchText->setPlaceholderText( i18nc( "Search Bar Click Message", "Search" ) ); m_searchText->setCompletionMode( KCompletion::CompletionPopup ); m_searchText->completionObject()->setIgnoreCase(true); m_searchAction = new QAction(this); m_searchAction->setText(i18nc("Kaction search label", "Search Modules")); m_searchAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-find"))); actionCollection()->addAction(QStringLiteral("search"),m_searchAction); actionCollection()->setDefaultShortcut(m_searchAction, QKeySequence(Qt::CTRL + Qt::Key_F)); m_sideMenu = new SidePanel(sideFrame); m_sideMenu->installEventFilter(this); menuLayout->addWidget(m_searchText); menuLayout->addWidget(m_sideMenu); m_splitter->addWidget(sideFrame); } void KInfoCenter::itemClickedSlot(const KcmTreeItem *item) { resetCondition(); if(item->type() != KcmTreeItem::CATEGORY) { setKcm(item); } } void KInfoCenter::setKcm(const KcmTreeItem *kcmItem) { if (m_contain->fileName() != kcmItem->kcm().fileName()) { m_contain->setKcm(kcmItem->kcm()); setButtons(m_contain->buttons()); m_aboutKcm->setEnabled(true); } } void KInfoCenter::setButtons(const KCModule::Buttons buttons) { if (buttons & KCModule::Help) { m_moduleHelpAction->setEnabled(true); } } void KInfoCenter::resetCondition() { m_moduleHelpAction->setEnabled(false); m_aboutKcm->setEnabled(false); } void KInfoCenter::helpClickedSlot() { // Nicked from Ben, could not use KToolInvocation due to docpath. QString docPath = m_contain->helpPath(); - QUrl url("help:/" + docPath ); + QUrl url(QStringLiteral("help:/") + docPath ); QProcess::startDetached(QStringLiteral("khelpcenter"), QStringList() << url.url()); } void KInfoCenter::aboutKcmSlot() { KAboutApplicationDialog kcmAboutDialog(*(m_contain->kcmAboutData())); kcmAboutDialog.exec(); } void KInfoCenter::showError(QWidget *parent, const QString& errorMessage) { KMessageBox::sorry(parent, errorMessage); } diff --git a/infokcmmodel.cpp b/infokcmmodel.cpp index 273c18f..fc391d0 100644 --- a/infokcmmodel.cpp +++ b/infokcmmodel.cpp @@ -1,231 +1,233 @@ /* * infokcmmodel.h * * Copyright (C) 2010 David Hubner * * 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. * */ //Local #include "infokcmmodel.h" #include "kcmcategoryitem.h" //KDE #include #include #include -InfoKcmModel::InfoKcmModel(QObject *parent) : QAbstractItemModel(parent), m_root(new KcmCategoryItem(i18n("Information Modules"))) +InfoKcmModel::InfoKcmModel(QObject *parent) + : QAbstractItemModel(parent), + m_root(new KcmCategoryItem(i18n("Information Modules"))) { createTreeItems(); } InfoKcmModel::~InfoKcmModel() { delete m_root; } void InfoKcmModel::createTreeItems() { - KService::List categoryList = KServiceTypeTrader::self()->query(QStringLiteral("KInfoCenterCategory")); + const KService::List categoryList = KServiceTypeTrader::self()->query(QStringLiteral("KInfoCenterCategory")); foreach(const KService::Ptr &categoryModule, categoryList) { m_root->addChild(new KcmCategoryItem(categoryModule,m_root)); } KService::List moduleList = KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-ParentApp] == 'kinfocenter'")); foreach(const KService::Ptr &kcmModule, moduleList) { if (kcmModule->isType(KST_KService) == true) { QString category = kcmModule->property(QStringLiteral("X-KDE-KInfoCenter-Category")).toString().trimmed(); if(!category.isEmpty() || !category.isNull()) { KcmTreeItem *item = m_root->containsCategory(category); if(item != NULL) { item->addChild(new KcmTreeItem(kcmModule,item)); } else { KcmTreeItem *lost = m_root->containsCategory(QStringLiteral("lost_and_found")); if(lost != NULL) { lost->addChild(new KcmTreeItem(kcmModule,lost)); } else { qWarning() << "Lost and found category not found, unable to display lost Kcontrol modules"; } } } else { m_root->addChild(new KcmTreeItem(kcmModule,m_root)); } } } } QModelIndex InfoKcmModel::index(int row, int column, const QModelIndex &parent) const { KcmTreeItem *parentItem; if (!parent.isValid()) { parentItem = m_root; } else { parentItem = static_cast(parent.internalPointer()); } KcmTreeItem *childItem = parentItem->child(row); if (childItem) { return createIndex(row, column, childItem); } return QModelIndex(); } QModelIndex InfoKcmModel::index(int row, int column, KcmTreeItem *parent) const { KcmTreeItem *childItem = parent->child(row); if (childItem) { return createIndex(row, column, childItem); } return QModelIndex(); } QModelIndex InfoKcmModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } KcmTreeItem *child = static_cast(index.internalPointer()); KcmTreeItem *parent = child->parent(); if (parent == m_root) { return QModelIndex(); } return createIndex(parent->row(), 0, parent); } QModelIndex InfoKcmModel::indexOf(KcmTreeItem *item) { QModelIndex tmpIndex = createIndex(item->row(), 0, item); if(!tmpIndex.isValid()) { return QModelIndex(); } return tmpIndex; } int InfoKcmModel::rowCount(const QModelIndex &parent) const { KcmTreeItem *parentItem; if (!parent.isValid()) { parentItem = m_root; } else { parentItem = static_cast(parent.internalPointer()); } return parentItem->childCount(); } int InfoKcmModel::columnCount(const QModelIndex &parent) const { // Hard coded, menu should never have more than one column Q_UNUSED(parent); return 1; } QVariant InfoKcmModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } KcmTreeItem *item = static_cast(index.internalPointer()); switch(role) { case Qt::DisplayRole: return item->data(); case Qt::UserRole: return item->weight(); case Qt::DecorationRole: return item->icon(); default: return QVariant(); } } QVariant InfoKcmModel::headerData(int section, Qt::Orientation orientation, int role) const { Q_UNUSED(section); if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { return m_root->data(); } return QVariant(); } Qt::ItemFlags InfoKcmModel::flags(const QModelIndex &index) const { if (!index.isValid()) { return Qt::ItemIsEnabled; } return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } QModelIndex InfoKcmModel::firstValid() const { int rows = m_root->childCount(); // Massive large number to max compare unsigned int winner = 0; winner--; QModelIndex winnerIndex = QModelIndex(); for(int i=0;ichild(i); if(item->type() == KcmTreeItem::KCM) { if(winner >= (unsigned int)item->weight()) { winner = item->weight(); winnerIndex = index(item->row(),0,item->parent()); } } } return winnerIndex; } QStringList InfoKcmModel::allChildrenKeywords() { return childrenKeywords(m_root); } QStringList InfoKcmModel::childrenKeywords(KcmTreeItem *kcmItem) { QStringList childKeywords; int rows = kcmItem->childCount(); for(int i=0;ichild(i); if(item->type() == KcmTreeItem::CATEGORY) { childKeywords = childKeywords + childrenKeywords(item); } else { childKeywords = childKeywords + item->keywords(); } } return childKeywords; } diff --git a/kcmcategoryitem.cpp b/kcmcategoryitem.cpp index c66b909..fb44838 100644 --- a/kcmcategoryitem.cpp +++ b/kcmcategoryitem.cpp @@ -1,85 +1,85 @@ /* * kcmcategoryitem.cpp * * Copyright (C) 2010 David Hubner * * 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. * */ #include "kcmcategoryitem.h" -KcmCategoryItem::KcmCategoryItem(const KService::Ptr module, KcmTreeItem *parent) : +KcmCategoryItem::KcmCategoryItem(const KService::Ptr &module, KcmTreeItem *parent) : KcmTreeItem(module, parent) { } KcmCategoryItem::KcmCategoryItem(const QString& categoryName) : KcmTreeItem(), m_category(categoryName) { } QString KcmCategoryItem::data() const { if(m_category.isEmpty()) { return m_moduleInfo->moduleName(); } return category(); } KcmTreeItem::itemType KcmCategoryItem::type() const { return CATEGORY; } QString KcmCategoryItem::category() const { if(m_category.isEmpty()) { return m_module->property(QStringLiteral("X-KDE-KInfoCenter-Category")).toString().trimmed(); } return m_category; } KCModuleInfo KcmCategoryItem::kcm() const { return KCModuleInfo(); } int KcmCategoryItem::weight() { return (category().count() + 1000); } QIcon KcmCategoryItem::icon() const { if(m_category.isEmpty()) { return QIcon::fromTheme(m_moduleInfo->icon()); } return QIcon(); } QString KcmCategoryItem::whatsThis() const { return QString(); } QStringList KcmCategoryItem::keywords() const { return QStringList(); } diff --git a/kcmcategoryitem.h b/kcmcategoryitem.h index d03cada..8d7e238 100644 --- a/kcmcategoryitem.h +++ b/kcmcategoryitem.h @@ -1,98 +1,98 @@ /* * kcmcategoryitem.h * * Copyright (C) 2010 David Hubner * * 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. * */ #ifndef KCMCATEGORYITEM #define KCMCATEGORYITEM #include "kcmtreeitem.h" //KDE #include #include class KcmCategoryItem : public KcmTreeItem { public: /** * Category Tree Item for InfoKcmModel. Holds information about a Category * * @param module pointer to KCM module * @param parent objects parent */ - explicit KcmCategoryItem(const KService::Ptr module, KcmTreeItem *parent=0); + explicit KcmCategoryItem(const KService::Ptr &module, KcmTreeItem *parent=nullptr); /** * Category Tree Item for InfoKcmModel. Holds information about a Category * * @note Used for root folder objects */ explicit KcmCategoryItem(const QString& category); /** * Get data of tree item */ QString data() const Q_DECL_OVERRIDE; /** * Get category of tree item. * Set in X-KDE-KInfoCenter-Category */ QString category() const Q_DECL_OVERRIDE; /** * Gets the item type. */ itemType type() const Q_DECL_OVERRIDE; /** * Get tree item KCMs Data */ KCModuleInfo kcm() const Q_DECL_OVERRIDE; /** * Get tree items KCM's weight */ int weight() Q_DECL_OVERRIDE; /** * Get icon tied to KCM */ QIcon icon() const Q_DECL_OVERRIDE; /** * Get whatsThis information from KCM */ QString whatsThis() const Q_DECL_OVERRIDE; /** * Get KCM tree item keywords */ QStringList keywords() const Q_DECL_OVERRIDE; private: const QString m_category; }; #endif //KCMCATEGORYITEM diff --git a/kcmcontainer.cpp b/kcmcontainer.cpp index 9572634..794870a 100644 --- a/kcmcontainer.cpp +++ b/kcmcontainer.cpp @@ -1,139 +1,139 @@ /* * kcmcontainer.cpp * * Copyright (C) 2010 David Hubner * * 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. * */ #include "kcmcontainer.h" //KDE #include //QT #include #include -KcmContainer::KcmContainer(QWidget *parent) : QScrollArea(parent), m_titleLabel(NULL), - m_centerWidget(NULL), m_mod(NULL), m_kcmTopEdge(-1) +KcmContainer::KcmContainer(QWidget *parent) : QScrollArea(parent), m_titleLabel(nullptr), + m_centerWidget(nullptr), m_mod(nullptr), m_kcmTopEdge(-1) { setWidgetResizable( true ); setFrameStyle( QFrame::NoFrame ); setContainerLayout(); } KcmContainer::~KcmContainer() { delete m_mod; } void KcmContainer::setContainerLayout() { if (!m_mod && m_centerWidget) { // we have no module, but a widget set up for one, // so just return for now return; } - m_mod = NULL; // will be deleted on the line below + m_mod = nullptr; // will be deleted on the line below delete m_centerWidget; m_centerWidget = new QWidget(this); m_centerWidget->setContentsMargins(0,0,0,0); QVBoxLayout *centerWidgetLayout = new QVBoxLayout(m_centerWidget); centerWidgetLayout->setContentsMargins(0, 0, 0, 0); QFont font; font.setPointSize(qRound(font.pointSize() * 1.4)); m_titleLabel = new QLabel(m_centerWidget); m_titleLabel->setFont(font); m_titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_titleLabel->setContentsMargins(style()->pixelMetric(QStyle::PM_DefaultFrameWidth), 0, 0, 0); m_titleLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); centerWidgetLayout->addWidget(m_titleLabel); setWidget(m_centerWidget); m_centerWidget->setAutoFillBackground(false); setKcmTopEdge(m_kcmTopEdge); } void KcmContainer::setKcm(const KCModuleInfo &info) { setContainerLayout(); m_mod = new KCModuleProxy(info); m_modInfo = info; setKcmTitle(info); m_mod->setWhatsThis(m_mod->quickHelp()); m_centerWidget->layout()->addWidget(m_mod); } void KcmContainer::setKcmTopEdge(int y) { m_kcmTopEdge = y; if (m_kcmTopEdge < 0) { return; } if (m_titleLabel) { int spacing = style()->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Vertical); m_titleLabel->setMinimumHeight(m_kcmTopEdge - spacing); } } void KcmContainer::setKcmTitle(const KCModuleInfo &info) { m_titleLabel->setText(info.comment()); } QString KcmContainer::helpPath() const { - if(m_mod == NULL) { + if(m_mod == nullptr) { return QString(); } return m_modInfo.docPath(); } KCModule::Buttons KcmContainer::buttons() const { return m_mod->buttons(); } const KAboutData *KcmContainer::kcmAboutData() const { return m_mod->aboutData(); } QString KcmContainer::exportText() const { return m_mod->realModule()->exportText(); } QString KcmContainer::name() const { return m_modInfo.moduleName(); } QString KcmContainer::fileName() const { return m_modInfo.fileName(); } diff --git a/kcmtreeitem.cpp b/kcmtreeitem.cpp index 1ce8647..f3b149d 100644 --- a/kcmtreeitem.cpp +++ b/kcmtreeitem.cpp @@ -1,154 +1,154 @@ /* * kcmtreeitem.h * * Copyright (C) 2010 David Hubner * * 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. * */ //Local #include "kcmtreeitem.h" KcmTreeItem::KcmTreeItem(const KService::Ptr module, KcmTreeItem *parent) : m_parent(parent), m_module(module), m_moduleInfo(new KCModuleInfo(m_module)) { } -KcmTreeItem::KcmTreeItem() : m_parent(NULL), m_moduleInfo(new KCModuleInfo()) +KcmTreeItem::KcmTreeItem() : m_parent(nullptr), m_moduleInfo(new KCModuleInfo()) { } KcmTreeItem::~KcmTreeItem() { qDeleteAll(m_children); delete m_moduleInfo; } void KcmTreeItem::addChild(KcmTreeItem *child) { m_children.append(child); } KcmTreeItem *KcmTreeItem::child(const int row) { if(childCount() > row) { return m_children.value(row); } return NULL; } int KcmTreeItem::childCount() { return m_children.count(); } int KcmTreeItem::columnCount() { // Hard coded, menu should never have more than one column return 1; } KcmTreeItem *KcmTreeItem::parent() { return m_parent; } int KcmTreeItem::row() { if (m_parent) { return indexOf(const_cast(this)); } return 0; } int KcmTreeItem::indexOf(KcmTreeItem *item) { if (m_parent) { return m_parent->m_children.indexOf(item); } return 0; } QString KcmTreeItem::data() const { return m_moduleInfo->moduleName(); } QString KcmTreeItem::category() const { return m_module->property(QStringLiteral("X-KDE-KInfoCenter-Category")).toString().trimmed(); } KcmTreeItem::itemType KcmTreeItem::type() const { return KCM; } KcmTreeItem *KcmTreeItem::containsCategory(const QString& category) { foreach(KcmTreeItem *item, m_children) { if(item->type() == CATEGORY) { if(item->category().contains(category)) { return item; } if(item->containsCategory(category)) { return item; } } } return NULL; } KCModuleInfo KcmTreeItem::kcm() const { return *m_moduleInfo; } int KcmTreeItem::weight() { return m_moduleInfo->weight(); } QIcon KcmTreeItem::icon() const { return QIcon::fromTheme(m_moduleInfo->icon()); } QString KcmTreeItem::whatsThis() const { return m_moduleInfo->comment(); } bool KcmTreeItem::childrenRegExp(const QRegExp& pattern) { foreach(KcmTreeItem *item, m_children) { if((item->keywords().filter(pattern).count() > 0) == true) { return true; } } return false; } QStringList KcmTreeItem::keywords() const { if(m_moduleInfo->keywords().isEmpty()) { return QStringList(data()); } return m_moduleInfo->keywords(); } diff --git a/main.cpp b/main.cpp index 34a9efa..44c1777 100644 --- a/main.cpp +++ b/main.cpp @@ -1,76 +1,76 @@ /* * main.cpp * * Copyright (C) 2010 David Hubner * * 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. * */ //Local #include "main.h" //KDE #include #include #include #include #include //Qt #include KicApp::KicApp(int &argc, char **argv) : QApplication(argc, argv) { KLocalizedString::setApplicationDomain("kinfocenter"); const auto displayName = i18n("Info Center"); KAboutData aboutData( QStringLiteral("kinfocenter"), displayName, PROJECT_VERSION, displayName, KAboutLicense::GPL, - i18n("Copyright 2009-2016 KDE")); + i18n("Copyright 2009-2017 KDE")); aboutData.addAuthor(i18n("David Hubner"),i18n("Current Maintainer"), QStringLiteral("hubnerd@ntlworld.com")); aboutData.addAuthor(i18n("Helge Deller"), i18n("Previous Maintainer"), QStringLiteral("deller@kde.org")); aboutData.addAuthor(i18n("Matthias Hoelzer-Kluepfel"),QString(), QStringLiteral("hoelzer@kde.org")); aboutData.addAuthor(i18n("Matthias Elter"), QString(), QStringLiteral("elter@kde.org")); aboutData.addAuthor(i18n("Matthias Ettrich"), QString(), QStringLiteral("ettrich@kde.org")); aboutData.addAuthor(i18n("Waldo Bastian"), QString(), QStringLiteral("bastian@kde.org")); aboutData.addAuthor(i18n("Nicolas Ternisien"), QString(), QStringLiteral("nicolas.ternisien@gmail.com")); KAboutData::setApplicationData(aboutData); QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo"))); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); aboutData.setupCommandLine(&parser); parser.process(*this); aboutData.processCommandLine(&parser); display = new KInfoCenter(); display->show(); - KDBusService* service = new KDBusService(KDBusService::Unique, this); + (void)new KDBusService(KDBusService::Unique, this); } int main(int argc, char *argv[]) { KicApp Kic(argc, argv); KCrash::initialize(); return Kic.exec(); } diff --git a/sidepanel.cpp b/sidepanel.cpp index a3a4510..93c3f2f 100644 --- a/sidepanel.cpp +++ b/sidepanel.cpp @@ -1,144 +1,145 @@ /* * sidepanel.cpp * * Copyright (C) 2010 David Hubner * * 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. * */ //Local #include "sidepanel.h" //KDE #include //QT #include #include #include -SidePanel::SidePanel(QWidget *parent) : QTreeView(parent) +SidePanel::SidePanel(QWidget *parent) + : QTreeView(parent) { setHeaderHidden(true); setSortingEnabled(true); setAnimated(true); sortByColumn(0, Qt::AscendingOrder); m_model = new InfoKcmModel(this); m_proxyModel = new InfoKcmProxyModel(this); m_proxyModel->setSourceModel(m_model); createMenuActions(); setMouseTracking(true); setModel(m_proxyModel); connect(this,SIGNAL(activated(QModelIndex)),this,SLOT(clickedSlot(QModelIndex))); connect(this,SIGNAL(clicked(QModelIndex)),this,SLOT(clickedSlot(QModelIndex))); } SidePanel::~SidePanel() { disconnect(this,SIGNAL(activated(QModelIndex)),this,SLOT(clickedSlot(QModelIndex))); disconnect(this,SIGNAL(clicked(QModelIndex)),this,SLOT(clickedSlot(QModelIndex))); delete m_proxyModel; delete m_model; } void SidePanel::clickedSlot(const QModelIndex &index) { if(index.isValid() == false) { return; } const KcmTreeItem *item = static_cast(m_proxyModel->mapToSource(index).internalPointer()); emit clicked(item); } void SidePanel::changeToFirstValidItem() { QModelIndex rootIndex = m_proxyModel->mapFromSource(m_model->firstValid()); if(rootIndex.isValid() == false) { return; } setCurrentIndex(rootIndex); emit clickedSlot(rootIndex); } QModelIndex SidePanel::mapToProxySource(const QModelIndex& index) { QModelIndex tmp = m_proxyModel->mapToSource(index); if(tmp.isValid() == true) { return tmp; } return QModelIndex(); } void SidePanel::filterSideMenuSlot(const QString &pattern) { if(pattern.isEmpty()) { collapseAll(); } else { expandAll(); } m_proxyModel->setFilterRegExp(QRegExp(pattern,Qt::CaseInsensitive)); } void SidePanel::createMenuActions() { resetAct = new QAction(i18n("Clear Search"), this); connect(resetAct, &QAction::triggered, this, &SidePanel::resetSearchSlot); expAct = new QAction(i18n("Expand All Categories"), this); connect(expAct, &QAction::triggered, this, &SidePanel::expandAllSlot); colAct = new QAction(i18n("Collapse All Categories"), this); connect(colAct, &QAction::triggered, this, &SidePanel::collapseAllSlot); } void SidePanel::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); menu.addAction(colAct); menu.addAction(expAct); menu.addAction(resetAct); menu.exec(event->globalPos()); } void SidePanel::collapseAllSlot() { collapseAll(); } void SidePanel::expandAllSlot() { expandAll(); } QStringList SidePanel::allChildKeywords() { return m_model->allChildrenKeywords(); } void SidePanel::resetSearchSlot() { filterSideMenuSlot(QLatin1String("")); }