garnacho / gtk-mpx

MPX-aware GTK+

gtk-mpx / tests / mpx / testphotoalbum.c
100644 113 lines (90 sloc) 3.077 kb
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
*
* This work is provided "as is"; redistribution and modification
* in whole or in part, in any medium, physical or electronic is
* permitted without restriction.
*
* This work 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.
*
* In no event shall the authors or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*/
 
#include <gtk/gtk.h>
#include "testphotoalbumwidget.h"
 
static void
add_image (TestPhotoAlbumWidget *album,
           const gchar *image_path)
{
  GdkPixbuf *pixbuf;
 
  pixbuf = gdk_pixbuf_new_from_file_at_size (image_path,
                                             200, -1,
                                             NULL);
  if (pixbuf)
    {
      test_photo_album_widget_add_image (album, pixbuf);
      g_object_unref (pixbuf);
    }
}
 
static void
read_directory (GFile *directory,
                TestPhotoAlbumWidget *album)
{
  GFileEnumerator *enumerator;
  GError *error = NULL;
  GFileInfo *info;
 
  enumerator = g_file_enumerate_children (directory,
                                          G_FILE_ATTRIBUTE_STANDARD_NAME,
                                          G_FILE_QUERY_INFO_NONE,
                                          NULL,
                                          &error);
 
  if (error)
    {
      g_warning ("%s\n", error->message);
      g_error_free (error);
      return;
    }
 
  while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
    {
      GFile *file;
      gchar *path;
 
      file = g_file_get_child (directory, g_file_info_get_name (info));
 
      path = g_file_get_path (file);
      add_image (album, path);
      g_free (path);
 
      g_object_unref (file);
    }
 
  g_file_enumerator_close (enumerator, NULL, NULL);
  g_object_unref (enumerator);
}
 
int
main (int argc, char *argv[])
{
  GtkWidget *window, *widget;
  GList *devices;
  GFile *dir;
 
  if (argc != 2)
    {
      g_print ("USAGE: %s <path-to-directory-with-images>\n", argv[0]);
      return -1;
    }
 
  gtk_init (&argc, &argv);
 
  dir = g_file_new_for_commandline_arg (argv[1]);
 
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
  widget = test_photo_album_widget_new ();
  gtk_container_add (GTK_CONTAINER (window), widget);
 
  g_signal_connect (window, "delete-event",
                    G_CALLBACK (gtk_main_quit), NULL);
 
  read_directory (dir, TEST_PHOTO_ALBUM_WIDGET (widget));
 
  gtk_widget_show_all (window);
 
  gtk_main ();
 
  return 0;
}