~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to gtk2_ardour/search_path_option.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2010 Paul Davis
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
#include "pbd/strsplit.h"
 
20
#include "pbd/compose.h"
 
21
#include "pbd/shortpath.h"
 
22
 
 
23
#include "search_path_option.h"
 
24
#include "i18n.h"
 
25
 
 
26
using namespace std;
 
27
using namespace Gtk;
 
28
 
 
29
SearchPathOption::SearchPathOption (const string& pathname, const string& label,
 
30
                                    const string& default_path,
 
31
                                    sigc::slot<std::string> get, sigc::slot<bool, std::string> set)
 
32
        : Option (pathname, label)
 
33
        , _get (get)
 
34
        , _set (set)
 
35
        , add_chooser (_("Select folder to search for media"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
 
36
{
 
37
        add_chooser.signal_file_set().connect (sigc::mem_fun (*this, &SearchPathOption::path_chosen));
 
38
 
 
39
        HBox* hbox = manage (new HBox);
 
40
 
 
41
        hbox->set_border_width (12);
 
42
        hbox->set_spacing (6);
 
43
        hbox->pack_end (add_chooser, true, true);
 
44
        hbox->pack_end (*manage (new Label (_("Click to add a new location"))), false, false);
 
45
        hbox->show_all ();
 
46
 
 
47
        vbox.pack_start (path_box);
 
48
        vbox.pack_end (*hbox);
 
49
 
 
50
        session_label.set_use_markup (true);
 
51
        session_label.set_markup (string_compose ("<i>%1 (%2)</i>", _("the session folder"), short_path (default_path, 32)));
 
52
        session_label.set_alignment (0.0, 0.5);
 
53
        session_label.show ();
 
54
 
 
55
        path_box.pack_start (session_label);
 
56
}
 
57
 
 
58
SearchPathOption::~SearchPathOption()
 
59
{
 
60
 
 
61
 
 
62
}
 
63
 
 
64
void
 
65
SearchPathOption::path_chosen ()
 
66
{
 
67
        string path = add_chooser.get_filename ();
 
68
        add_path (path);
 
69
        changed ();
 
70
}
 
71
 
 
72
void
 
73
SearchPathOption::add_to_page (OptionEditorPage* p)
 
74
{
 
75
        int const n = p->table.property_n_rows();
 
76
        p->table.resize (n + 1, 3);
 
77
 
 
78
        Label* label = manage (new Label);
 
79
        label->set_alignment (0.0, 0.0);
 
80
        label->set_text (string_compose ("%1", _name));
 
81
 
 
82
        p->table.attach (*label, 1, 2, n, n + 1, FILL | EXPAND);
 
83
        p->table.attach (vbox, 2, 3, n, n + 1, FILL | EXPAND);
 
84
}
 
85
 
 
86
void
 
87
SearchPathOption::clear ()
 
88
{
 
89
        path_box.remove (session_label);
 
90
        for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
 
91
                path_box.remove ((*p)->box);
 
92
                delete *p;
 
93
        }
 
94
        paths.clear ();
 
95
}
 
96
 
 
97
void
 
98
SearchPathOption::set_state_from_config ()
 
99
{
 
100
        string str = _get ();
 
101
        vector<string> dirs;
 
102
 
 
103
        clear ();
 
104
        path_box.pack_start (session_label);
 
105
 
 
106
        split (str, dirs, ':');
 
107
 
 
108
        for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); ++d) {
 
109
                add_path (*d);
 
110
        }
 
111
}
 
112
 
 
113
void
 
114
SearchPathOption::changed ()
 
115
{
 
116
        string str;
 
117
 
 
118
        for (list<PathEntry*>::iterator p = paths.begin(); p != paths.end(); ++p) {
 
119
 
 
120
                if (!str.empty()) {
 
121
                        str += ':';
 
122
                }
 
123
                str += (*p)->entry.get_text ();
 
124
        }
 
125
 
 
126
        _set (str);
 
127
}
 
128
 
 
129
void
 
130
SearchPathOption::add_path (const string& path, bool removable)
 
131
{
 
132
        PathEntry* pe = new PathEntry (path, removable);
 
133
        paths.push_back (pe);
 
134
        path_box.pack_start (pe->box, false, false);
 
135
        pe->remove_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &SearchPathOption::remove_path), pe));
 
136
}
 
137
 
 
138
void
 
139
SearchPathOption::remove_path (PathEntry* pe)
 
140
{
 
141
        path_box.remove (pe->box);
 
142
        paths.remove (pe);
 
143
        delete pe;
 
144
        changed ();
 
145
}
 
146
 
 
147
SearchPathOption::PathEntry::PathEntry (const std::string& path, bool removable)
 
148
        : remove_button (Stock::REMOVE)
 
149
{
 
150
        entry.set_text (path);
 
151
        entry.show ();
 
152
 
 
153
        box.set_spacing (6);
 
154
        box.set_homogeneous (false);
 
155
        box.pack_start (entry, true, true);
 
156
 
 
157
        if (removable) {
 
158
                box.pack_start (remove_button, false, false);
 
159
                remove_button.show ();
 
160
        }
 
161
 
 
162
        box.show ();
 
163
}