~ubuntu-branches/ubuntu/precise/gtkmm3.0/precise

« back to all changes in this revision

Viewing changes to gtk/src/printsettings.ccg

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-17 00:12:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110617001244-9hl5an15hiaaahi6
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2006 The gtkmm Development Team
 
2
 *
 
3
 * This library is free software; you can redistribute it and/or
 
4
 * modify it under the terms of the GNU Lesser General Public
 
5
 * License as published by the Free Software Foundation; either
 
6
 * version 2.1 of the License, or (at your option) any later version.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library; if not, write to the Free
 
15
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
16
 */
 
17
 
 
18
#include <glibmm/vectorutils.h>
 
19
 
 
20
#include <gtk/gtk.h>
 
21
 
 
22
#include <glib.h>
 
23
 
 
24
namespace // anonymous
 
25
{
 
26
 
 
27
static void proxy_foreach_callback(const gchar* key, const gchar* value, void* data)
 
28
{
 
29
  typedef Gtk::PrintSettings::SlotForeach SlotType;
 
30
  SlotType& slot = *static_cast<SlotType*>(data);
 
31
 
 
32
  try
 
33
  {
 
34
    slot(Glib::convert_const_gchar_ptr_to_ustring(key), Glib::convert_const_gchar_ptr_to_ustring(value));
 
35
  }
 
36
  catch(...)
 
37
  {
 
38
    Glib::exception_handlers_invoke();
 
39
  }
 
40
}
 
41
 
 
42
} // anonymous namespace
 
43
 
 
44
namespace Gtk
 
45
{
 
46
 
 
47
//Initialize static members:
 
48
const Glib::ustring PrintSettings::Keys::PRINTER = GTK_PRINT_SETTINGS_PRINTER;
 
49
const Glib::ustring PrintSettings::Keys::ORIENTATION = GTK_PRINT_SETTINGS_ORIENTATION;
 
50
const Glib::ustring PrintSettings::Keys::PAPER_FORMAT = GTK_PRINT_SETTINGS_PAPER_FORMAT;
 
51
const Glib::ustring PrintSettings::Keys::PAPER_WIDTH = GTK_PRINT_SETTINGS_PAPER_WIDTH;
 
52
const Glib::ustring PrintSettings::Keys::PAPER_HEIGHT = GTK_PRINT_SETTINGS_PAPER_HEIGHT;
 
53
const Glib::ustring PrintSettings::Keys::NUM_COPIES = GTK_PRINT_SETTINGS_N_COPIES;
 
54
const Glib::ustring PrintSettings::Keys::DEFAULT_SOURCE = GTK_PRINT_SETTINGS_DEFAULT_SOURCE;
 
55
const Glib::ustring PrintSettings::Keys::QUALITY = GTK_PRINT_SETTINGS_QUALITY;
 
56
const Glib::ustring PrintSettings::Keys::RESOLUTION = GTK_PRINT_SETTINGS_RESOLUTION;
 
57
const Glib::ustring PrintSettings::Keys::USE_COLOR = GTK_PRINT_SETTINGS_USE_COLOR;
 
58
const Glib::ustring PrintSettings::Keys::DUPLEX = GTK_PRINT_SETTINGS_DUPLEX;
 
59
const Glib::ustring PrintSettings::Keys::COLLATE = GTK_PRINT_SETTINGS_COLLATE;
 
60
const Glib::ustring PrintSettings::Keys::REVERSE = GTK_PRINT_SETTINGS_REVERSE;
 
61
const Glib::ustring PrintSettings::Keys::MEDIA_TYPE = GTK_PRINT_SETTINGS_MEDIA_TYPE;
 
62
const Glib::ustring PrintSettings::Keys::DITHER = GTK_PRINT_SETTINGS_DITHER;
 
63
const Glib::ustring PrintSettings::Keys::SCALE = GTK_PRINT_SETTINGS_SCALE;
 
64
const Glib::ustring PrintSettings::Keys::PRINT_PAGES = GTK_PRINT_SETTINGS_PRINT_PAGES;
 
65
const Glib::ustring PrintSettings::Keys::PAGE_RANGES = GTK_PRINT_SETTINGS_PAGE_RANGES;
 
66
const Glib::ustring PrintSettings::Keys::PAGE_SET = GTK_PRINT_SETTINGS_PAGE_SET;
 
67
const Glib::ustring PrintSettings::Keys::FINISHINGS = GTK_PRINT_SETTINGS_FINISHINGS;
 
68
const Glib::ustring PrintSettings::Keys::NUMBER_UP = GTK_PRINT_SETTINGS_NUMBER_UP;
 
69
const Glib::ustring PrintSettings::Keys::OUTPUT_BIN = GTK_PRINT_SETTINGS_OUTPUT_BIN;
 
70
 
 
71
const Glib::ustring PrintSettings::Keys::OUTPUT_FILE_FORMAT = GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT;
 
72
const Glib::ustring PrintSettings::Keys::OUTPUT_URI = GTK_PRINT_SETTINGS_OUTPUT_URI;
 
73
 
 
74
const Glib::ustring PrintSettings::Keys::WIN32_DRIVER_VERSION = GTK_PRINT_SETTINGS_WIN32_DRIVER_VERSION;
 
75
const Glib::ustring PrintSettings::Keys::WIN32_DRIVER_EXTRA = GTK_PRINT_SETTINGS_WIN32_DRIVER_EXTRA;
 
76
 
 
77
Glib::RefPtr<PrintSettings> PrintSettings::create_from_key_file(const Glib::KeyFile& key_file)
 
78
{
 
79
  Glib::RefPtr<PrintSettings> result = PrintSettings::create();
 
80
 
 
81
  result->load_from_key_file(key_file);
 
82
 
 
83
  return result;
 
84
}
 
85
 
 
86
Glib::RefPtr<PrintSettings> PrintSettings::create_from_key_file(const Glib::KeyFile& key_file, const Glib::ustring& group_name)
 
87
{
 
88
  Glib::RefPtr<PrintSettings> result = PrintSettings::create();
 
89
 
 
90
  result->load_from_key_file(key_file, group_name);
 
91
 
 
92
  return result;
 
93
}
 
94
 
 
95
Glib::RefPtr<PrintSettings> PrintSettings::create_from_file(const std::string& file_name)
 
96
{
 
97
  Glib::RefPtr<PrintSettings> result = PrintSettings::create();
 
98
 
 
99
  result->load_from_file(file_name);
 
100
 
 
101
  return result;
 
102
}
 
103
 
 
104
void PrintSettings::setting_foreach(const SlotForeach& slot)
 
105
{
 
106
  SlotForeach slot_copy(slot);
 
107
  gtk_print_settings_foreach(const_cast<GtkPrintSettings*>(gobj()), &proxy_foreach_callback, &slot_copy);
 
108
}
 
109
 
 
110
PrintSettings::PageRange::PageRange()
 
111
:
 
112
  start(0),
 
113
  end(0)
 
114
{}
 
115
 
 
116
PrintSettings::PageRange::PageRange(int start_, int end_)
 
117
:
 
118
  start(start_),
 
119
  end(end_)
 
120
{}
 
121
 
 
122
std::vector<PrintSettings::PageRange> PrintSettings::get_page_ranges() const
 
123
{
 
124
  int num_ranges (0);
 
125
  GtkPageRange* page_ranges =
 
126
    gtk_print_settings_get_page_ranges(const_cast<GtkPrintSettings*>(gobj()), &num_ranges);
 
127
 
 
128
  // no need for deep ownership.
 
129
  return Glib::ArrayHandler<PageRange, PageRangeTraits>::array_to_vector(page_ranges, num_ranges, Glib::OWNERSHIP_SHALLOW);
 
130
}
 
131
 
 
132
void PrintSettings::set_page_ranges(const std::vector<PrintSettings::PageRange>& page_ranges)
 
133
{
 
134
  gtk_print_settings_set_page_ranges(gobj(),
 
135
                                     Glib::ArrayHandler<PageRange, PageRangeTraits>::vector_to_array(page_ranges).data (),
 
136
                                     page_ranges.size ());
 
137
}
 
138
 
 
139
 
 
140
bool PrintSettings::load_from_key_file(const Glib::KeyFile& key_file)
 
141
{
 
142
  GError* gerror = 0;
 
143
  bool retvalue = gtk_print_settings_load_key_file(gobj(), const_cast<GKeyFile*>((key_file).gobj()), NULL, &(gerror));
 
144
  if(gerror)
 
145
    ::Glib::Error::throw_exception(gerror);
 
146
 
 
147
  return retvalue;
 
148
}
 
149
 
 
150
void PrintSettings::save_to_key_file(Glib::KeyFile& key_file) const
 
151
{
 
152
  gtk_print_settings_to_key_file(const_cast<GtkPrintSettings*>(gobj()), (key_file).gobj(), 0); 
 
153
}
 
154
 
 
155
} // namespace Gtk