generic: cleanup libtaskmanager

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2016-08-15 13:36:17 +00:00
parent cf8dd960a7
commit 9ac6ec69f7
7 changed files with 15 additions and 194 deletions

View file

@ -737,8 +737,7 @@ void GroupManagerPrivate::sycocaChanged(const QStringList &types)
if (types.contains("apps")) {
KUrl::List removals;
foreach (LauncherItem *launcher, launchers) {
if (launcher->launcherUrl().protocol() != "preferred" &&
!QFile::exists(launcher->launcherUrl().toLocalFile())) {
if (!QFile::exists(launcher->launcherUrl().toLocalFile())) {
removals << launcher->launcherUrl();
}
}
@ -1013,13 +1012,7 @@ void GroupManagerPrivate::unsaveLauncher(LauncherItem *launcher)
return;
}
QString launcherKey;
if (launcher->launcherUrl().protocol() == "preferred")
// in default config the host of the preferred application url is used as key
launcherKey = launcher->launcherUrl().host();
else
launcherKey = launcher->name();
QString launcherKey = launcher->name();
if (cg.hasKey(launcherKey)) {
cg.deleteEntry(launcherKey);
@ -1083,27 +1076,6 @@ int GroupManagerPrivate::launcherIndex(const KUrl &url)
++index;
}
// .. and if that fails for preferred launcher matches
index = 0;
foreach (const LauncherItem * item, launchers) {
if (item->launcherUrl().protocol() == "preferred") {
KService::Ptr service = KService::serviceByStorageId(item->defaultApplication());
if (service) {
QUrl prefUrl(service->entryPath());
if (prefUrl.scheme().isEmpty()) {
prefUrl.setScheme("file");
}
if (prefUrl == url) {
return index;
}
}
}
++index;
}
return -1;
}

View file

@ -189,18 +189,12 @@ QString LauncherItem::wmClass() const
void LauncherItem::setName(const QString& name)
{
//NOTE: preferred is NOT a protocol, it's just a magic string
if (d->url.protocol() != "preferred") {
d->name = name;
}
}
void LauncherItem::setGenericName(const QString& genericName)
{
//NOTE: preferred is NOT a protocol, it's just a magic string
if (d->url.protocol() != "preferred") {
d->genericName = genericName;
}
}
void LauncherItem::setWmClass(const QString &wmClass)
@ -215,22 +209,7 @@ ItemType LauncherItem::itemType() const
void LauncherItem::launch()
{
//NOTE: preferred is NOT a protocol, it's just a magic string
if (d->url.protocol() == "preferred") {
KService::Ptr service = KService::serviceByStorageId(defaultApplication());
if (!service) {
return;
}
QString desktopFile = KStandardDirs::locate("xdgdata-apps", service->entryPath());
if (desktopFile.isNull()) {
desktopFile = KStandardDirs::locate("apps", service->entryPath());
}
new KRun(desktopFile, 0);
} else {
new KRun(d->url, 0);
}
}
void LauncherItem::addMimeData(QMimeData* mimeData) const
@ -243,100 +222,13 @@ KUrl LauncherItem::launcherUrl() const
return d->url;
}
//Ugly hack written by Aaron Seigo from plasmagenericshell/scripting/scriptengine.cpp
QString LauncherItem::defaultApplication() const
{
const QString application = d->url.host();
if (application.isEmpty()) {
return QString();
}
// FIXME: there are some pretty horrible hacks below, in the sense that they assume a very
// specific implementation system. there is much room for improvement here. see
// kdebase-runtime/kcontrol/componentchooser/ for all the gory details ;)
if (application.compare("mailer", Qt::CaseInsensitive) == 0) {
KEMailSettings settings;
// in KToolInvocation, the default is kmail; but let's be friendlier :)
QString command = settings.getSetting(KEMailSettings::ClientProgram);
if (command.isEmpty()) {
if (KService::Ptr kontact = KService::serviceByStorageId("kontact")) {
return kontact->storageId();
} else if (KService::Ptr kmail = KService::serviceByStorageId("kmail")) {
return kmail->storageId();
}
}
if (!command.isEmpty()) {
if (settings.getSetting(KEMailSettings::ClientTerminal) == "true") {
KConfigGroup confGroup(KGlobal::config(), "General");
const QString preferredTerminal = confGroup.readPathEntry("TerminalApplication",
QString::fromLatin1("konsole"));
command = preferredTerminal + QString::fromLatin1(" -e ") + command;
}
return command;
}
} else if (application.compare("browser", Qt::CaseInsensitive) == 0) {
KConfigGroup config(KGlobal::config(), "General");
QString browserApp = config.readPathEntry("BrowserApplication", QString());
if (browserApp.isEmpty()) {
const KService::Ptr htmlApp = KMimeTypeTrader::self()->preferredService(QLatin1String("text/html"));
if (htmlApp) {
browserApp = htmlApp->storageId();
}
} else if (browserApp.startsWith('!')) {
browserApp = browserApp.mid(1);
}
return browserApp;
} else if (application.compare("terminal", Qt::CaseInsensitive) == 0) {
KConfigGroup confGroup(KGlobal::config(), "General");
return confGroup.readPathEntry("TerminalApplication", QString::fromLatin1("konsole"));
} else if (application.compare("filemanager", Qt::CaseInsensitive) == 0) {
KService::Ptr service = KMimeTypeTrader::self()->preferredService("inode/directory");
if (service) {
return service->storageId();
}
} else if (application.compare("windowmanager", Qt::CaseInsensitive) == 0) {
KConfig cfg("ksmserverrc", KConfig::NoGlobals);
KConfigGroup confGroup(&cfg, "General");
return confGroup.readEntry("windowManager", QString::fromLatin1("kwin"));
} else if (KService::Ptr service = KMimeTypeTrader::self()->preferredService(application)) {
return service->storageId();
} else {
// try the files in share/apps/kcm_componentchooser/
const QStringList services = KGlobal::dirs()->findAllResources("data", "kcm_componentchooser/*.desktop", KStandardDirs::NoDuplicates);
//kDebug() << "ok, trying in" << services.count();
foreach (const QString & service, services) {
KConfig config(service, KConfig::SimpleConfig);
KConfigGroup cg = config.group(QByteArray());
const QString type = cg.readEntry("valueName", QString());
//kDebug() << " checking" << service << type << application;
if (type.compare(application, Qt::CaseInsensitive) == 0) {
KConfig store(cg.readPathEntry("storeInFile", "null"));
KConfigGroup storeCg(&store, cg.readEntry("valueSection", QString()));
const QString exec = storeCg.readPathEntry(cg.readEntry("valueName", "kcm_componenchooser_null"),
cg.readEntry("defaultImplementation", QString()));
if (!exec.isEmpty()) {
return exec;
}
break;
}
}
}
return "";
}
void LauncherItem::setLauncherUrl(const KUrl &url)
{
// Takes care of improperly escaped characters and resolves paths
// into file:/// URLs
KUrl newUrl(url.url());
if (d->url.protocol() != "preferred" && newUrl == d->url) {
if (newUrl == d->url) {
return;
}
@ -353,31 +245,6 @@ void LauncherItem::setLauncherUrl(const KUrl &url)
d->url = KUrl();
return;
}
} else if (d->url.protocol() == "preferred") {
//NOTE: preferred is NOT a protocol, it's just a magic string
const KService::Ptr service = KService::serviceByStorageId(defaultApplication());
if (service) {
QString desktopFile = KStandardDirs::locate("xdgdata-apps", service->entryPath());
if (desktopFile.isNull()) {
desktopFile = KStandardDirs::locate("apps", service->entryPath());
}
KDesktopFile f(desktopFile);
KConfigGroup cg(&f, "Desktop Entry");
d->icon = KIcon(f.readIcon());
const QString exec = cg.readEntry("Exec", QString());
d->name = cg.readEntry("Name", QString());
if (d->name.isEmpty() && !exec.isEmpty()) {
d->name = exec.split(' ').at(0);
}
d->genericName = f.readGenericName();
d->resolvedUrl = desktopFile;
d->resolvedUrl.setScheme("file");
} else {
d->url = KUrl();
}
} else {
d->icon = KIcon(KMimeType::iconNameForUrl(d->url));
}
@ -398,10 +265,7 @@ bool LauncherItem::isValid() const
void LauncherItem::setIcon(const QIcon& icon)
{
//NOTE: preferred is NOT a protocol, it's just a magic string
if (d->url.protocol() != "preferred") {
d->icon = icon;
}
}
bool LauncherItem::demandsAttention() const

View file

@ -89,9 +89,6 @@ public:
KUrl launcherUrl() const;
void setLauncherUrl(const KUrl &url);
//preferred applications hack
QString defaultApplication() const;
public Q_SLOTS:
void toDesktop(int);

View file

@ -189,11 +189,6 @@ bool Task::isMinimized() const
return d->info.valid(true) && d->info.isMinimized();
}
bool Task::isIconified() const
{
return d->info.valid(true) && d->info.isMinimized();
}
bool Task::isAlwaysOnTop() const
{
return d->info.valid(true) && (d->info.state() & NET::KeepAbove);
@ -500,7 +495,7 @@ void Task::setIconified(bool iconify)
void Task::toggleIconified()
{
setIconified(!isIconified());
setIconified(!isMinimized());
}
void Task::raise()
@ -543,8 +538,8 @@ void Task::activate()
void Task::activateRaiseOrIconify()
{
//kDebug() << isActive() << isIconified() << isOnTop();
if (!isActive() || isIconified()) {
//kDebug() << isActive() << isMinimized() << isOnTop();
if (!isActive() || isMinimized()) {
activate();
} else if (!isOnTop()) {
raise();

View file

@ -59,7 +59,6 @@ class TASKMANAGER_EXPORT Task : public QObject
Q_PROPERTY(bool maximized READ isMaximized)
Q_PROPERTY(bool minimized READ isMinimized)
// KDE4 deprecated
Q_PROPERTY(bool iconified READ isIconified)
Q_PROPERTY(bool shaded READ isShaded WRITE setShaded)
Q_PROPERTY(bool active READ isActive)
Q_PROPERTY(bool onCurrentDesktop READ isOnCurrentDesktop)
@ -162,12 +161,6 @@ public:
*/
bool isMinimized() const;
/**
* @deprecated
* Returns true if the task's window is minimized(iconified).
*/
bool isIconified() const;
/**
* Returns true if the task's window is shaded.
*/
@ -179,7 +172,7 @@ public:
bool isActive() const;
/**
* Returns true if the task's window is the topmost non-iconified,
* Returns true if the task's window is the topmost non-minimized,
* non-always-on-top window.
*/
bool isOnTop() const;
@ -307,7 +300,7 @@ public Q_SLOTS:
void toggleMaximized();
/**
* Restore the main window of the task (if it was iconified).
* Restore the main window of the task (if it was minimized).
*/
void restore();

View file

@ -201,7 +201,7 @@ Task *TaskManager::findTask(int desktop, const QPoint& p)
continue;
}
if (t->isIconified() || t->isShaded()) {
if (t->isMinimized() || t->isShaded()) {
continue;
}
@ -503,7 +503,7 @@ bool TaskManager::isOnTop(const Task *task) const
continue;
}
if (!t->isIconified() && (t->isAlwaysOnTop() == task->isAlwaysOnTop())) {
if (!t->isMinimized() && (t->isAlwaysOnTop() == task->isAlwaysOnTop())) {
return false;
}
}

View file

@ -596,7 +596,7 @@ void WebBrowser::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *opt
Q_UNUSED(option)
Q_UNUSED(contentsRect)
if (!isIconified()){
if (!isMinimized()){
p->save();
p->setBrush(QApplication::palette().window());
p->setRenderHint(QPainter::Antialiasing);