summaryrefslogtreecommitdiff
path: root/src/selection.cpp
blob: 7e15a9e93cdf16f6d232c59c5abf340e75643e90 (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
#include <config.h>

#include "selection.h"
#include "proctable.h"
#include "util.h"

namespace procman
{
    void SelectionMemento::add_to_selected(GtkTreeModel* model, GtkTreePath*, GtkTreeIter* iter, gpointer data)
    {
        guint pid = 0;
        gtk_tree_model_get(model, iter, COL_PID, &pid, -1);
        if (pid)
            static_cast<SelectionMemento*>(data)->pids.push_back(pid);
    }


    void SelectionMemento::save(GtkWidget* tree)
    {
        GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
        gtk_tree_selection_selected_foreach(selection, &SelectionMemento::add_to_selected, this);
    }


    void SelectionMemento::restore(GtkWidget* tree)
    {
        if (not this->pids.empty())
        {
            GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
            typedef std::vector<pid_t>::iterator iterator;
            for (iterator it(this->pids.begin()); it != this->pids.end(); ++it)
            {
                if (ProcInfo* proc = ProcInfo::find(*it))
                {
                    gtk_tree_selection_select_iter(selection, &proc->node);
                    procman_debug("Re-selected process %u", unsigned(*it));
                }
                else
                    procman_debug("Could not find process %u, cannot re-select it", unsigned(*it));
            }
        }
    }
}