/*************************************************************************** * Copyright (C) 2007 by Robert Knight * * Copyright (C) 2008 by Alexis Ménard * * * * 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 "tooltips/tooltipmanager.h" // Own #include "tasks.h" #include "windowtaskitem.h" #include "taskgroupitem.h" #include "jobmanager.h" #include "dockmanager.h" #include "mediabuttons.h" #include "unity.h" #include "recentdocuments.h" //Taskmanager #include "taskmanager/groupmanager.h" #include "taskmanager/taskgroup.h" #include "taskmanager/taskitem.h" // KDE #include #include #include // Qt #include #include #include #include #include #include // Plasma #include #include #include #include static void renameConfig() { // Rename pre0.9 taskmanagerrc to taskmanagerrulesrc QString oldName = KStandardDirs::locateLocal("config", "taskmanagerrc"); if (QFile::exists(oldName)) { QString newName = KStandardDirs::locateLocal("config", "taskmanagerrulesrc"); if (QFile::exists(newName)) { QFile::remove(oldName); } else { QFile::rename(oldName, newName); } } } static void setCurrentIndex(QComboBox *combo, int val) { for (int i = 0; i < combo->count(); ++i) { if (combo->itemData(i).toInt() == val) { combo->setCurrentIndex(i); break; } } } class GroupManager : public TaskManager::GroupManager { public: GroupManager(Plasma::Applet *applet) : TaskManager::GroupManager(applet), m_applet(applet) { setGroupingStrategy(GroupManager::ProgramGrouping); setSortingStrategy(GroupManager::ManualSorting); setShowOnlyCurrentDesktop(true); setShowOnlyCurrentScreen(false); setShowOnlyMinimized(false); setOnlyGroupWhenFull(false); setSeparateLaunchers(false); setForceGrouping(true); readLauncherConfig(); } protected: KConfigGroup config() const { return m_applet->config(); } private: Plasma::Applet *m_applet; }; static const int constMinSpacing = 0; static const int constMaxSpacing = 50; static const int constMinIconScale = 49; static const int constMaxIconScale = 100; Tasks::Tasks(QObject* parent, const QVariantList &arguments) : Plasma::Applet(parent, arguments), m_toolTips(TT_Instant), m_highlightWindows(true), m_launcherIcons(false), m_groupClick(GC_PresentWindows), m_rotate(false), m_style(Style_Plasma), m_showSeparator(Sep_WhenNeeded), m_middleClick(MC_NewInstance), m_spacing(0), m_iconScale(constMinIconScale), // constMinIconScale==automatic scaling!!! m_taskItemBackground(0), m_progressBar(0), m_badgeBackground(0), m_indicators(0), m_leftMargin(0), m_topMargin(0), m_rightMargin(0), m_bottomMargin(0), m_offscreenLeftMargin(0), m_offscreenTopMargin(0), m_offscreenRightMargin(0), m_offscreenBottomMargin(0), m_rootGroupItem(0), m_groupManager(0), m_lockAct(0), m_unlockAct(0), m_refreshAct(0) { KGlobal::locale()->insertCatalog("icontasks"); renameConfig(); setHasConfigurationInterface(true); setAspectRatioMode(Plasma::IgnoreAspectRatio); m_screenTimer.setSingleShot(true); m_screenTimer.setInterval(300); resize(500, 58); setAcceptDrops(true); } Tasks::~Tasks() { JobManager::self()->setEnabled(false); DockManager::self()->setEnabled(false); MediaButtons::self()->setEnabled(false); Unity::self()->setEnabled(false); RecentDocuments::self()->setEnabled(false); delete m_rootGroupItem; delete m_groupManager; AbstractTaskItem::clearCaches(); } void Tasks::init() { m_groupManager = new GroupManager(this); Plasma::Containment* appletContainment = containment(); if (appletContainment) { m_groupManager->setScreen(appletContainment->screen()); } connect(m_groupManager, SIGNAL(reload()), this, SLOT(reload())); connect(m_groupManager, SIGNAL(configChanged()), this, SIGNAL(configNeedsSaving())); m_rootGroupItem = new TaskGroupItem(this, this); m_rootGroupItem->expand(); m_rootGroupItem->setGroup(m_groupManager->rootGroup()); connect(m_rootGroupItem, SIGNAL(sizeHintChanged(Qt::SizeHint)), this, SLOT(changeSizeHint(Qt::SizeHint))); setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); setMaximumSize(INT_MAX, INT_MAX); layout = new QGraphicsLinearLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); layout->setMaximumSize(INT_MAX, INT_MAX); layout->setOrientation(Qt::Vertical); layout->addItem(m_rootGroupItem); setLayout(layout); configChanged(); if (containment()) { IconTasks::ToolTipManager::self()->setCorona(containment()->corona()); } } void Tasks::configChanged() { KConfigGroup cg = config(); bool changed = false; // only update these if they have actually changed, because they make the // group manager reload its tasks list const bool showOnlyCurrentDesktop = cg.readEntry("showOnlyCurrentDesktop", m_groupManager->showOnlyCurrentDesktop()); if (showOnlyCurrentDesktop != m_groupManager->showOnlyCurrentDesktop()) { m_groupManager->setShowOnlyCurrentDesktop(showOnlyCurrentDesktop); changed = true; } const bool showOnlyCurrentScreen = cg.readEntry("showOnlyCurrentScreen", m_groupManager->showOnlyCurrentScreen()); if (showOnlyCurrentScreen != m_groupManager->showOnlyCurrentScreen()) { m_groupManager->setShowOnlyCurrentScreen(showOnlyCurrentScreen); changed = true; } TaskManager::GroupManager::TaskSortingStrategy sortingStrategy = static_cast( cg.readEntry("sortingStrategy", static_cast(m_groupManager->sortingStrategy())) ); if (sortingStrategy != m_groupManager->sortingStrategy()) { m_groupManager->setSortingStrategy(sortingStrategy); changed = true; } const int maxRows = cg.readEntry("maxRows", m_rootGroupItem->maxRows()); if (maxRows != m_rootGroupItem->maxRows()) { m_rootGroupItem->setMaxRows(maxRows); changed = true; } const bool launcherIcons = cg.readEntry("launcherIcons", m_launcherIcons); if (launcherIcons != m_launcherIcons) { m_launcherIcons = launcherIcons; changed = true; } const GroupClick groupClick = static_cast(cg.readEntry("groupClick", static_cast(m_groupClick))); if (groupClick != m_groupClick) { m_groupClick = groupClick; changed = true; } const bool rotate = cg.readEntry("rotate", m_rotate); if (rotate != m_rotate) { m_rotate = rotate; changed = true; } const Style style = static_cast