summaryrefslogtreecommitdiff
path: root/Userland/Services/Taskbar/QuickLaunchWidget.h
blob: d5497c5c54a824b7964bb3e5b031c5d5a529e32b (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2021, Fabian Blatz <fabianblatz@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Error.h>
#include <AK/RefPtr.h>
#include <LibConfig/Listener.h>
#include <LibCore/FileWatcher.h>
#include <LibDesktop/AppFile.h>
#include <LibGUI/Button.h>
#include <LibGUI/Frame.h>

namespace Taskbar {

class QuickLaunchEntry {
public:
    virtual ~QuickLaunchEntry() = default;
    virtual ErrorOr<void> launch() const = 0;
    virtual GUI::Icon icon() const = 0;
    virtual DeprecatedString name() const = 0;
    virtual DeprecatedString file_name_to_watch() const = 0;

    static OwnPtr<QuickLaunchEntry> create_from_config_value(StringView path);
    static OwnPtr<QuickLaunchEntry> create_from_path(StringView path);
};

class QuickLaunchEntryAppFile : public QuickLaunchEntry {
public:
    explicit QuickLaunchEntryAppFile(NonnullRefPtr<Desktop::AppFile> file)
        : m_app_file(move(file))
    {
    }

    virtual ErrorOr<void> launch() const override;
    virtual GUI::Icon icon() const override { return m_app_file->icon(); }
    virtual DeprecatedString name() const override { return m_app_file->name(); }
    virtual DeprecatedString file_name_to_watch() const override { return {}; }

private:
    NonnullRefPtr<Desktop::AppFile> m_app_file;
};

class QuickLaunchEntryExecutable : public QuickLaunchEntry {
public:
    explicit QuickLaunchEntryExecutable(DeprecatedString path)
        : m_path(move(path))
    {
    }

    virtual ErrorOr<void> launch() const override;
    virtual GUI::Icon icon() const override;
    virtual DeprecatedString name() const override;
    virtual DeprecatedString file_name_to_watch() const override { return m_path; }

private:
    DeprecatedString m_path;
};
class QuickLaunchEntryFile : public QuickLaunchEntry {
public:
    explicit QuickLaunchEntryFile(DeprecatedString path)
        : m_path(move(path))
    {
    }

    virtual ErrorOr<void> launch() const override;
    virtual GUI::Icon icon() const override;
    virtual DeprecatedString name() const override;
    virtual DeprecatedString file_name_to_watch() const override { return m_path; }

private:
    DeprecatedString m_path;
};

class QuickLaunchWidget : public GUI::Frame
    , public Config::Listener {
    C_OBJECT(QuickLaunchWidget);

public:
    static ErrorOr<NonnullRefPtr<QuickLaunchWidget>> create();
    virtual ~QuickLaunchWidget() override = default;

    virtual void config_key_was_removed(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
    virtual void config_string_did_change(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;

    virtual void drag_enter_event(GUI::DragEvent&) override;
    virtual void drop_event(GUI::DropEvent&) override;

private:
    explicit QuickLaunchWidget();
    ErrorOr<void> add_or_adjust_button(DeprecatedString const&, NonnullOwnPtr<QuickLaunchEntry>&&);
    ErrorOr<void> create_context_menu();
    ErrorOr<void> add_quick_launch_buttons(Vector<NonnullOwnPtr<QuickLaunchEntry>> entries);

    RefPtr<GUI::Menu> m_context_menu;
    RefPtr<GUI::Action> m_context_menu_default_action;
    DeprecatedString m_context_menu_app_name;
    RefPtr<Core::FileWatcher> m_watcher;
};

}