summaryrefslogtreecommitdiff
path: root/src/mainwindow/taskmanager.cpp
blob: 9025f461d717e0f37c4c3bca0c1faad57fdec9f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ============================================================
 *     The rekonq project
 * ============================================================
 * SPDX-License-Identifier: GPL-3.0-only
 * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
 * ============================================================
 * Description: Task Manager
 * ============================================================ */

#include "taskmanager.h"
#include "application.hpp"
#include "plugins/pluginloader.h"
#include "ui_taskmanager.h"

TaskManager::TaskManager(QWidget *parent) : QDialog(parent), ui(new Ui::TaskManager)
{
  ui->setupUi(this);
  ui->pluginStateBox->setVisible(false);

  auto *app = Application::instance();

  // Plugins Tab
  auto pluginList = app->pluginList();
  for (auto &plugin : pluginList) {
    auto *item = new QListWidgetItem(plugin->fileName(), ui->plugins);
    item->setData(Qt::UserRole, QVariant::fromValue(plugin));
  }
  connect(ui->plugins, &QListWidget::itemClicked, this, &TaskManager::showPluginDetails);
  connect(ui->pluginState, &QPushButton::clicked, [this](bool checked) {
    auto *item = ui->plugins->currentItem();
    auto plugin = item->data(Qt::UserRole).value<QPointer<PluginLoader>>();
    Q_CHECK_PTR(plugin);

    if (checked) plugin->load();
    else
      plugin->unload();

    showPluginDetails(item);
  });

  // Windows Tab
  const auto windowList = app->windowList();
  for (const auto &window : windowList) ui->windows->addItem(window->windowTitle());

  // Views Tab
  const auto viewList = app->viewList();
  for (const auto &view : viewList) ui->views->addItem(view->title());
}

TaskManager::~TaskManager() { delete ui; }

void TaskManager::showPluginDetails(QListWidgetItem *item)
{
  auto plugin = item->data(Qt::UserRole).value<QPointer<PluginLoader>>();
  Q_CHECK_PTR(plugin);

  ui->pluginStateBox->setVisible(true);
  ui->pluginState->setText(plugin->isLoaded() ? tr("Loaded") : tr("Not loaded"));
  ui->pluginState->setChecked(plugin->isLoaded());
  ui->pluginError->setText(plugin->errorString());
  ui->pluginSchemes->setText(plugin->schemes().join(' '));
}