[gtkmm-documentation] Add a PlacesSidebar example.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Add a PlacesSidebar example.
- Date: Mon, 23 Sep 2013 12:15:30 +0000 (UTC)
commit c5276342f1bf228957fc391f543ad1ce32e6ab83
Author: Juan R. Garcia Blanco <juanrgar gmail com>
Date: Mon Sep 23 13:51:46 2013 +0200
Add a PlacesSidebar example.
* examples/book/placessidebar/examplewindow.[h|cc]:
* exampels/book/placessidebar/main.cc: New files.
* examples/Makefile.am: Mention the new example and its files.
examples/Makefile.am | 6 +
examples/book/placessidebar/examplewindow.cc | 134 ++++++++++++++++++++++++++
examples/book/placessidebar/examplewindow.h | 55 +++++++++++
examples/book/placessidebar/main.cc | 29 ++++++
4 files changed, 224 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 87a0d32..b4a591e 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -77,6 +77,7 @@ check_PROGRAMS = \
book/multithread/example \
book/notebook/example \
book/paned/example \
+ book/placessidebar/example \
book/printing/advanced/example \
book/printing/simple/example \
book/progressbar/example \
@@ -499,6 +500,11 @@ book_paned_example_SOURCES = \
book/paned/messagetext.cc \
book/paned/messagetext.h
+book_placessidebar_example_SOURCES = \
+ book/placessidebar/examplewindow.cc \
+ book/placessidebar/examplewindow.h \
+ book/placessidebar/main.cc
+
book_printing_advanced_example_SOURCES = \
book/printing/advanced/examplewindow.cc \
book/printing/advanced/examplewindow.h \
diff --git a/examples/book/placessidebar/examplewindow.cc b/examples/book/placessidebar/examplewindow.cc
new file mode 100644
index 0000000..ef765fa
--- /dev/null
+++ b/examples/book/placessidebar/examplewindow.cc
@@ -0,0 +1,134 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "examplewindow.h"
+
+ExampleWindow::ExampleWindow()
+: m_hbox(Gtk::ORIENTATION_HORIZONTAL, 6),
+ m_show_desktop_check("Show desktop"),
+ m_show_connect_to_server_check("Show connect to server")
+{
+ // Window properties
+ set_title("PlacesSidebar Example");
+ set_border_width(12);
+ set_size_request(300, 600);
+
+ // Options
+ m_controls_frame.set_shadow_type(Gtk::SHADOW_NONE);
+ m_frame_label.set_markup("<b>Options</b>");
+ m_controls_frame.set_label_widget(m_frame_label);
+ m_alignment.set_padding(6, 0, 12, 0);
+
+ m_show_desktop_check.signal_toggled().connect(sigc::mem_fun(*this,
&ExampleWindow::on_show_desktop_toggled));
+ m_show_desktop_check.set_active(true);
+
+ m_show_connect_to_server_check.signal_toggled().connect(sigc::mem_fun(*this,
&ExampleWindow::on_show_connect_to_server_toggled));
+ m_show_connect_to_server_check.set_active(true);
+
+ m_places_sidebar.signal_open_location().connect(sigc::mem_fun(*this, &ExampleWindow::on_open_location));
+ m_places_sidebar.signal_populate_popup().connect(sigc::mem_fun(*this, &ExampleWindow::on_populate_popup));
+ m_places_sidebar.signal_drag_action_requested().connect(sigc::mem_fun(*this,
&ExampleWindow::on_drag_action_requested));
+
+ m_controls.attach(m_show_desktop_check, 0, 0, 1, 1);
+ m_controls.attach(m_show_connect_to_server_check, 0, 1, 1, 1);
+
+ std::cout << "Shortcuts:" << std::endl;
+ std::vector<Glib::RefPtr<Gio::File > > shortcuts = m_places_sidebar.list_shortcuts();
+ for (std::vector<Glib::RefPtr<Gio::File > >::const_iterator it = shortcuts.begin();
+ it != shortcuts.end(); ++it) {
+ std::cout << "basename: " << (*it)->get_basename() << std::endl;
+ }
+
+ // Layout
+ m_controls_frame.add(m_alignment);
+ m_alignment.add(m_controls);
+ m_hbox.pack_start(m_places_sidebar, true, true, 0);
+ m_hbox.pack_start(m_controls_frame, false, false, 0);
+ add(m_hbox);
+
+ show_all_children();
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_show_desktop_toggled()
+{
+ bool show_desktop = m_show_desktop_check.get_active();
+
+ m_places_sidebar.set_show_desktop(show_desktop);
+}
+
+void ExampleWindow::on_show_connect_to_server_toggled()
+{
+ bool show_connect_to_server = m_show_connect_to_server_check.get_active();
+
+ m_places_sidebar.set_show_connect_to_server(show_connect_to_server);
+}
+
+void ExampleWindow::on_open_location(const Glib::RefPtr<Gio::File>& location, Gtk::PlacesOpenFlags
open_flags)
+{
+ Gtk::MessageDialog dialog(*this, "<b>open-location</b> event triggered", true);
+ Gtk::Grid location_information_grid;
+ Gtk::Label basename_label("Basename:", Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
+ Gtk::Label path_label("Path:", Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
+ Gtk::Label uri_label("URI:", Gtk::ALIGN_END, Gtk::ALIGN_CENTER);
+ Gtk::Label file_basename_label, file_path_label, file_uri_label;
+
+ file_basename_label.set_text(location->get_basename());
+ file_basename_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
+ file_path_label.set_text(location->get_path());
+ file_path_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
+ file_uri_label.set_text(location->get_uri());
+ file_uri_label.set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
+
+ location_information_grid.attach(basename_label, 0, 0, 1, 1);
+ location_information_grid.attach(file_basename_label, 1, 0, 1, 1);
+ location_information_grid.attach(path_label, 0, 1, 1, 1);
+ location_information_grid.attach(file_path_label, 1, 1, 1, 1);
+ location_information_grid.attach(uri_label, 0, 2, 1, 1);
+ location_information_grid.attach(file_uri_label, 1, 2, 1, 1);
+
+ location_information_grid.set_column_spacing(6);
+
+ dialog.get_content_area()->pack_end(location_information_grid, true, true, 6);
+ dialog.show_all();
+ dialog.run();
+}
+
+void ExampleWindow::on_populate_popup(Gtk::Menu* menu, const Glib::RefPtr<Gio::File>& selected_item, const
Glib::RefPtr<Gio::Volume>& selected_volume)
+{
+ Gtk::MenuItem* properties_menu_item = new Gtk::MenuItem("Properties...");
+
+ properties_menu_item->signal_activate().connect(sigc::mem_fun(*this,
&ExampleWindow::on_properties_activate));
+ properties_menu_item->show();
+
+ menu->attach(*properties_menu_item, 0, 1, 0, 1);
+}
+
+void ExampleWindow::on_properties_activate()
+{
+ Glib::RefPtr< Gio::File> selected_item = m_places_sidebar.get_location();
+
+ on_open_location(selected_item, Gtk::PLACES_OPEN_NORMAL);
+}
+
+
+int ExampleWindow::on_drag_action_requested(const Glib::RefPtr<Gdk::DragContext>& context, const
Glib::RefPtr<Gio::File>& dest_file, const std::vector< Glib::RefPtr<Gio::File> >& source_file_list)
+{
+}
+
diff --git a/examples/book/placessidebar/examplewindow.h b/examples/book/placessidebar/examplewindow.h
new file mode 100644
index 0000000..f954807
--- /dev/null
+++ b/examples/book/placessidebar/examplewindow.h
@@ -0,0 +1,55 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+
+#include <iostream>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+ ExampleWindow();
+ virtual ~ExampleWindow();
+
+protected:
+ // Slots
+ void on_show_desktop_toggled();
+ void on_show_connect_to_server_toggled();
+ void on_open_location(const Glib::RefPtr<Gio::File>& location, Gtk::PlacesOpenFlags open_flags);
+ void on_populate_popup(Gtk::Menu* menu, const Glib::RefPtr<Gio::File>& selected_item, const
Glib::RefPtr<Gio::Volume>& selected_volume);
+ int on_drag_action_requested(const Glib::RefPtr<Gdk::DragContext>& context, const Glib::RefPtr<Gio::File>&
dest_file, const std::vector< Glib::RefPtr<Gio::File> >& source_file_list);
+ void on_properties_activate();
+
+ // Containers
+ Gtk::Box m_hbox;
+ Gtk::Grid m_controls;
+ Gtk::Frame m_controls_frame;
+ Gtk::Label m_frame_label;
+ Gtk::Alignment m_alignment;
+
+ // Widgets
+ Gtk::PlacesSidebar m_places_sidebar;
+ Gtk::CheckButton m_show_desktop_check;
+ Gtk::CheckButton m_show_connect_to_server_check;
+
+private:
+};
+
+#endif // GTKMM_EXAMPLEWINDOW_H
+
diff --git a/examples/book/placessidebar/main.cc b/examples/book/placessidebar/main.cc
new file mode 100644
index 0000000..2153055
--- /dev/null
+++ b/examples/book/placessidebar/main.cc
@@ -0,0 +1,29 @@
+/* gtkmm example Copyright (C) 2013 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "placessidebarwindow.h"
+#include <gtkmm/application.h>
+
+int main(int argc, char *argv[])
+{
+ Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv,
"org.gtkmm.example.placessidebar");
+
+ PlacesSidebarWindow window;
+
+ // Shows the window and returns when it is closed.
+ return app->run(window);
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]