2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
6 * RawTherapee is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * RawTherapee is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
19 #include <favoritbrowser.h>
21 FavoritBrowser::FavoritBrowser () : listener (NULL
), lastSelectedDir ("") {
23 scrollw
= Gtk::manage (new Gtk::ScrolledWindow ());
24 scrollw
->set_policy (Gtk::POLICY_NEVER
, Gtk::POLICY_AUTOMATIC
);
26 Gtk::Frame
* frame
= Gtk::manage (new Gtk::Frame ("Favorite Folders"));
27 frame
->add (*scrollw
);
31 treeView
= Gtk::manage (new Gtk::TreeView ());
32 scrollw
->add (*treeView
);
34 favoritModel
= Gtk::ListStore::create (favoritColumns
);
35 treeView
->set_model (favoritModel
);
36 treeView
->set_headers_visible (false);
38 Gtk::TreeView::Column
*iviewcol
= Gtk::manage (new Gtk::TreeView::Column ("icon"));
39 Gtk::CellRendererPixbuf
*iconCR
= Gtk::manage (new Gtk::CellRendererPixbuf());
40 iviewcol
->pack_start (*iconCR
, false);
41 iviewcol
->add_attribute (*iconCR
, "gicon", 0);
43 treeView
->append_column (*iviewcol
);
44 treeView
->append_column ("text", favoritColumns
.shortdir
);
46 treeView
->set_tooltip_column (2);
47 treeView
->get_selection()->signal_changed().connect(sigc::mem_fun(*this, &FavoritBrowser::selectionChanged
));
49 add
= Gtk::manage (new Gtk::Button ("Add"));
50 del
= Gtk::manage (new Gtk::Button ("Del"));
51 add
->set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::ADD
, Gtk::ICON_SIZE_MENU
)));
52 del
->set_image (*Gtk::manage (new Gtk::Image (Gtk::Stock::REMOVE
, Gtk::ICON_SIZE_MENU
)));
53 Gtk::HBox
* buttonBox
= Gtk::manage (new Gtk::HBox ());
54 buttonBox
->pack_start (*add
);
55 buttonBox
->pack_start (*del
);
57 pack_start (*buttonBox
, Gtk::PACK_SHRINK
, 2);
59 add
->signal_clicked().connect(sigc::mem_fun(*this, &FavoritBrowser::addPressed
));
60 del
->signal_clicked().connect(sigc::mem_fun(*this, &FavoritBrowser::delPressed
));
65 void FavoritBrowser::selectionChanged () {
67 Glib::RefPtr
<Gtk::TreeSelection
> selection
= treeView
->get_selection();
68 Gtk::TreeModel::iterator iter
= selection
->get_selected();
70 listener
->selectDir (iter
->get_value (favoritColumns
.fulldir
));
73 void FavoritBrowser::dirSelected (const Glib::ustring
& dirname
, const Glib::ustring
& openfile
) {
75 lastSelectedDir
= dirname
;
78 void FavoritBrowser::addPressed () {
80 if (lastSelectedDir
=="")
83 // check if the dirname is already in the list. If yes, return.
84 Gtk::TreeModel::iterator iter
= favoritModel
->children ().begin();
85 while (iter
!= favoritModel
->children().end()) {
86 if (iter
->get_value (favoritColumns
.fulldir
) == lastSelectedDir
)
91 Glib::RefPtr
<Gio::File
> hfile
= Gio::File::create_for_parse_name (lastSelectedDir
);
93 Glib::RefPtr
<Gio::FileInfo
> info
= hfile
->query_info ();
95 Gtk::TreeModel::Row newrow
= *(favoritModel
->append());
96 newrow
[favoritColumns
.shortdir
] = info
->get_display_name ();
97 newrow
[favoritColumns
.fulldir
] = lastSelectedDir
;
98 newrow
[favoritColumns
.icon
] = info
->get_icon ();
103 void FavoritBrowser::delPressed () {
105 // lookup the selected item in the bookmark
106 Glib::RefPtr
<Gtk::TreeSelection
> selection
= treeView
->get_selection();
107 Gtk::TreeModel::iterator iter
= selection
->get_selected();
110 favoritModel
->erase (iter
);