gtkmm-documentation r35 - in trunk: . examples/book/giomm examples/book/giomm/usage
- From: jjongsma svn gnome org
- To: svn-commits-list gnome org
- Subject: gtkmm-documentation r35 - in trunk: . examples/book/giomm examples/book/giomm/usage
- Date: Sat, 23 Feb 2008 05:12:20 +0000 (GMT)
Author: jjongsma
Date: Sat Feb 23 05:12:19 2008
New Revision: 35
URL: http://svn.gnome.org/viewvc/gtkmm-documentation?rev=35&view=rev
Log:
* configure.in:
* examples/book/giomm/Makefile.am:
* examples/book/giomm/usage/Makefile.am:
* examples/book/giomm/usage/usage.cc: add another simple giomm example --
this one just takes a directory argument on the command line at recursively
calculates the size of the files in that directory
Added:
trunk/examples/book/giomm/usage/ (props changed)
trunk/examples/book/giomm/usage/Makefile.am
trunk/examples/book/giomm/usage/usage.cc
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/examples/book/giomm/Makefile.am
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Sat Feb 23 05:12:19 2008
@@ -312,6 +312,7 @@
examples/book/giomm/volumes/Makefile
examples/book/giomm/getline/Makefile
examples/book/giomm/monitor_directory/Makefile
+ examples/book/giomm/usage/Makefile
examples/book/frame/Makefile
examples/book/helloworld/Makefile
examples/book/helloworld2/Makefile
Modified: trunk/examples/book/giomm/Makefile.am
==============================================================================
--- trunk/examples/book/giomm/Makefile.am (original)
+++ trunk/examples/book/giomm/Makefile.am Sat Feb 23 05:12:19 2008
@@ -1 +1 @@
-SUBDIRS = directory_list read_file volumes getline monitor_directory
+SUBDIRS = directory_list read_file volumes getline monitor_directory usage
Added: trunk/examples/book/giomm/usage/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/examples/book/giomm/usage/Makefile.am Sat Feb 23 05:12:19 2008
@@ -0,0 +1,6 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = usage
+usage_SOURCES = usage.cc
+
Added: trunk/examples/book/giomm/usage/usage.cc
==============================================================================
--- (empty file)
+++ trunk/examples/book/giomm/usage/usage.cc Sat Feb 23 05:12:19 2008
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2008 Jonathon Jongsma
+ *
+ * This file is part of gtkmm
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ *
+ *******************************************************************************/
+#include <giomm.h>
+#include <iostream>
+
+goffset get_size_recursively (const Glib::RefPtr<Gio::File>& file)
+{
+ goffset total = 0;
+ g_return_val_if_fail (file, total);
+ try {
+ Glib::RefPtr<Gio::FileInfo> info = file->query_info ();
+ if (info->get_file_type () == Gio::FILE_TYPE_DIRECTORY)
+ {
+ Glib::RefPtr<Gio::FileEnumerator> children = file->enumerate_children ();
+ Glib::RefPtr<Gio::FileInfo> child_info;
+ while (child_info = children->next_file ())
+ {
+ goffset size = get_size_recursively (
+ file->get_child (child_info->get_name ()));
+ total += size;
+ }
+ //std::cout << file->get_path () << ": " << total << std::endl;
+ }
+ else
+ {
+ total = info->get_size ();
+ }
+ }
+ catch (const Glib::Error& error)
+ {
+ std::cerr << error.what () << std::endl;
+ }
+ return total;
+}
+
+int main(int argc, char** argv)
+{
+ std::string root_dir = ".";
+ if (argc > 1) {
+ root_dir = argv[1];
+ }
+ Gio::init ();
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_path (root_dir);
+ std::cout << "Gathering disk usage information for '" << file->get_path () << "'" << std::endl;
+ goffset total = get_size_recursively (file);
+ std::cout << "Total: " << total << std::endl;
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]