* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
+
#include <string.h>
#include <stdlib.h>
+
#include <glib/gprintf.h>
+
#include "gtkprintsettings.h"
#include "gtkprintutils.h"
-#include "gtkalias.h"
+#include "gtktypebuiltins.h"
+#include "gtkwidget.h"
+
+
+/**
+ * SECTION:gtkprintsettings
+ * @Short_description: Stores print settings
+ * @Title: GtkPrintSettings
+ *
+ * A GtkPrintSettings object represents the settings of a print dialog in
+ * a system-independent way. The main use for this object is that once
+ * you've printed you can get a settings object that represents the settings
+ * the user chose, and the next time you print you can pass that object in so
+ * that the user doesn't have to re-set all his settings.
+ *
+ * Its also possible to enumerate the settings so that you can easily save
+ * the settings for the next time your app runs, or even store them in a
+ * document. The predefined keys try to use shared values as much as possible
+ * so that moving such a document between systems still works.
+ *
+ * <!-- TODO example of getting, storing and setting settings -->
+ *
+ * Printing support was added in GTK+ 2.10.
+ */
typedef struct _GtkPrintSettingsClass GtkPrintSettingsClass;
struct _GtkPrintSettings
{
GObject parent_instance;
-
+
GHashTable *hash;
};
/**
* gtk_print_settings_copy:
* @other: a #GtkPrintSettings
- *
+ *
* Copies a #GtkPrintSettings object.
- *
- * Return value: a newly allocated copy of @other
+ *
+ * Return value: (transfer full): a newly allocated copy of @other
*
* Since: 2.10
*/
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get (GtkPrintSettings *settings,
const gchar *key)
{
* gtk_print_settings_set:
* @settings: a #GtkPrintSettings
* @key: a key
- * @value: a string value, or %NULL
- *
+ * @value: (allow-none): a string value, or %NULL
+ *
* Associates @value with @key.
*
- * Since: 2.10
+ * Since: 2.10
*/
void
gtk_print_settings_set (GtkPrintSettings *settings,
const gchar *val;
val = gtk_print_settings_get (settings, key);
- if (val != NULL && strcmp (val, "true") == 0)
+ if (g_strcmp0 (val, "true") == 0)
return TRUE;
return FALSE;
const gchar *val;
val = gtk_print_settings_get (settings, key);
- if (val != NULL && strcmp (val, "true") == 0)
+ if (g_strcmp0 (val, "true") == 0)
return TRUE;
- if (val != NULL && strcmp (val, "false") == 0)
+ if (g_strcmp0 (val, "false") == 0)
return FALSE;
return default_val;
/**
* gtk_print_settings_foreach:
* @settings: a #GtkPrintSettings
- * @func: the function to call
+ * @func: (scope call): the function to call
* @user_data: user data for @func
- *
+ *
* Calls @func for each key-value pair of @settings.
*
* Since: 2.10
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get_printer (GtkPrintSettings *settings)
{
return gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_PRINTER);
gboolean
gtk_print_settings_get_collate (GtkPrintSettings *settings)
{
- return gtk_print_settings_get_bool (settings,
- GTK_PRINT_SETTINGS_COLLATE);
+ return gtk_print_settings_get_bool_with_default (settings,
+ GTK_PRINT_SETTINGS_COLLATE,
+ TRUE);
}
/**
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_PAGE_SET, str);
}
+/**
+ * gtk_print_settings_get_number_up_layout:
+ * @settings: a #GtkPrintSettings
+ *
+ * Gets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
+ *
+ * Return value: layout of page in number-up mode
+ *
+ * Since: 2.14
+ */
+GtkNumberUpLayout
+gtk_print_settings_get_number_up_layout (GtkPrintSettings *settings)
+{
+ GtkNumberUpLayout layout;
+ GtkTextDirection text_direction;
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ const gchar *val;
+
+ g_return_val_if_fail (GTK_IS_PRINT_SETTINGS (settings), GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
+
+ val = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT);
+ text_direction = gtk_widget_get_default_direction ();
+
+ if (text_direction == GTK_TEXT_DIR_LTR)
+ layout = GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM;
+ else
+ layout = GTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM;
+
+ if (val == NULL)
+ return layout;
+
+ enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
+ enum_value = g_enum_get_value_by_nick (enum_class, val);
+ if (enum_value)
+ layout = enum_value->value;
+ g_type_class_unref (enum_class);
+
+ return layout;
+}
+
+/**
+ * gtk_print_settings_set_number_up_layout:
+ * @settings: a #GtkPrintSettings
+ * @number_up_layout: a #GtkNumberUpLayout value
+ *
+ * Sets the value of %GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT.
+ *
+ * Since: 2.14
+ */
+void
+gtk_print_settings_set_number_up_layout (GtkPrintSettings *settings,
+ GtkNumberUpLayout number_up_layout)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ g_return_if_fail (GTK_IS_PRINT_SETTINGS (settings));
+
+ enum_class = g_type_class_ref (GTK_TYPE_NUMBER_UP_LAYOUT);
+ enum_value = g_enum_get_value (enum_class, number_up_layout);
+ g_return_if_fail (enum_value != NULL);
+
+ gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT, enum_value->value_nick);
+ g_type_class_unref (enum_class);
+}
+
/**
* gtk_print_settings_get_n_copies:
* @settings: a #GtkPrintSettings
gint
gtk_print_settings_get_number_up (GtkPrintSettings *settings)
{
- return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_NUMBER_UP);
+ return gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_NUMBER_UP, 1);
}
/**
gint
gtk_print_settings_get_resolution (GtkPrintSettings *settings)
{
- return gtk_print_settings_get_int (settings, GTK_PRINT_SETTINGS_RESOLUTION);
+ return gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION, 300);
}
/**
* @settings: a #GtkPrintSettings
* @resolution: the resolution in dpi
*
- * Sets the value of %GTK_PRINT_SETTINGS_RESOLUTION.
+ * Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
+ * %GTK_PRINT_SETTINGS_RESOLUTION_X and
+ * %GTK_PRINT_SETTINGS_RESOLUTION_Y.
*
* Since: 2.10
*/
{
gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
resolution);
+ gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
+ resolution);
+ gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
+ resolution);
+}
+
+/**
+ * gtk_print_settings_get_resolution_x:
+ * @settings: a #GtkPrintSettings
+ *
+ * Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_X.
+ *
+ * Return value: the horizontal resolution in dpi
+ *
+ * Since: 2.16
+ */
+gint
+gtk_print_settings_get_resolution_x (GtkPrintSettings *settings)
+{
+ return gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_X, 300);
+}
+
+/**
+ * gtk_print_settings_get_resolution_y:
+ * @settings: a #GtkPrintSettings
+ *
+ * Gets the value of %GTK_PRINT_SETTINGS_RESOLUTION_Y.
+ *
+ * Return value: the vertical resolution in dpi
+ *
+ * Since: 2.16
+ */
+gint
+gtk_print_settings_get_resolution_y (GtkPrintSettings *settings)
+{
+ return gtk_print_settings_get_int_with_default (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y, 300);
+}
+
+/**
+ * gtk_print_settings_set_resolution_xy:
+ * @settings: a #GtkPrintSettings
+ * @resolution_x: the horizontal resolution in dpi
+ * @resolution_y: the vertical resolution in dpi
+ *
+ * Sets the values of %GTK_PRINT_SETTINGS_RESOLUTION,
+ * %GTK_PRINT_SETTINGS_RESOLUTION_X and
+ * %GTK_PRINT_SETTINGS_RESOLUTION_Y.
+ *
+ * Since: 2.16
+ */
+void
+gtk_print_settings_set_resolution_xy (GtkPrintSettings *settings,
+ gint resolution_x,
+ gint resolution_y)
+{
+ gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_X,
+ resolution_x);
+ gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION_Y,
+ resolution_y);
+ gtk_print_settings_set_int (settings, GTK_PRINT_SETTINGS_RESOLUTION,
+ resolution_x);
+}
+
+/**
+ * gtk_print_settings_get_printer_lpi:
+ * @settings: a #GtkPrintSettings
+ *
+ * Gets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
+ *
+ * Return value: the resolution in lpi (lines per inch)
+ *
+ * Since: 2.16
+ */
+gdouble
+gtk_print_settings_get_printer_lpi (GtkPrintSettings *settings)
+{
+ return gtk_print_settings_get_double_with_default (settings, GTK_PRINT_SETTINGS_PRINTER_LPI, 150.0);
+}
+
+/**
+ * gtk_print_settings_set_printer_lpi:
+ * @settings: a #GtkPrintSettings
+ * @lpi: the resolution in lpi (lines per inch)
+ *
+ * Sets the value of %GTK_PRINT_SETTINGS_PRINTER_LPI.
+ *
+ * Since: 2.16
+ */
+void
+gtk_print_settings_set_printer_lpi (GtkPrintSettings *settings,
+ gdouble lpi)
+{
+ gtk_print_settings_set_double (settings, GTK_PRINT_SETTINGS_PRINTER_LPI,
+ lpi);
}
/**
if (val == NULL || (strcmp (val, "all") == 0))
return GTK_PRINT_PAGES_ALL;
+ if (strcmp (val, "selection") == 0)
+ return GTK_PRINT_PAGES_SELECTION;
+
if (strcmp (val, "current") == 0)
return GTK_PRINT_PAGES_CURRENT;
case GTK_PRINT_PAGES_CURRENT:
str = "current";
break;
+ case GTK_PRINT_PAGES_SELECTION:
+ str = "selection";
+ break;
case GTK_PRINT_PAGES_RANGES:
str = "ranges";
break;
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_PRINT_PAGES, str);
}
-
+
/**
* gtk_print_settings_get_page_ranges:
* @settings: a #GtkPrintSettings
- * @num_ranges: return location for the length of the returned array
- *
+ * @num_ranges: (out): return location for the length of the returned array
+ *
* Gets the value of %GTK_PRINT_SETTINGS_PAGE_RANGES.
- *
- * Return value: an array of #GtkPageRange<!-- -->s. Use g_free()
- * to free the array when it is no longer needed.
+ *
+ * Return value: (array length=num_ranges) (transfer full): an array
+ * of #GtkPageRange<!-- -->s. Use g_free() to free the array when
+ * it is no longer needed.
*
* Since: 2.10
*/
{
str++;
end = (gint)strtol (str, NULL, 10);
- if (end < start)
- end = start;
}
ranges[i].start = start;
/**
* gtk_print_settings_set_page_ranges:
* @settings: a #GtkPrintSettings
- * @page_ranges: an array of #GtkPageRange<!-- -->s
+ * @page_ranges: (array length=num_ranges): an array of #GtkPageRange<!-- -->s
* @num_ranges: the length of @page_ranges
*
* Sets the value of %GTK_PRINT_SETTINGS_PAGE_RANGES.
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get_default_source (GtkPrintSettings *settings)
{
return gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_DEFAULT_SOURCE);
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get_media_type (GtkPrintSettings *settings)
{
return gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_MEDIA_TYPE);
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get_dither (GtkPrintSettings *settings)
{
return gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_DITHER);
*
* Since: 2.10
*/
-G_CONST_RETURN gchar *
+const gchar *
gtk_print_settings_get_output_bin (GtkPrintSettings *settings)
{
return gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_BIN);
/**
* gtk_print_settings_load_file:
* @settings: a #GtkPrintSettings
- * @file_name: the filename to read the settings from
- * @error: return location for errors, or %NULL
+ * @file_name: (type filename): the filename to read the settings from
+ * @error: (allow-none): return location for errors, or %NULL
*
- * Reads the print settings from @file_name.
+ * Reads the print settings from @file_name. If the file could not be loaded
+ * then error is set to either a #GFileError or #GKeyFileError.
* See gtk_print_settings_to_file().
*
* Return value: %TRUE on success
/**
* gtk_print_settings_new_from_file:
- * @file_name: the filename to read the settings from
- * @error: return location for errors, or %NULL
+ * @file_name: (type filename): the filename to read the settings from
+ * @error: (allow-none): return location for errors, or %NULL
*
* Reads the print settings from @file_name. Returns a new #GtkPrintSettings
- * object with the restored settings, or %NULL if an error occurred.
- * See gtk_print_settings_to_file().
+ * object with the restored settings, or %NULL if an error occurred. If the
+ * file could not be loaded then error is set to either a #GFileError or
+ * #GKeyFileError. See gtk_print_settings_to_file().
*
* Return value: the restored #GtkPrintSettings
*
* gtk_print_settings_load_key_file:
* @settings: a #GtkPrintSettings
* @key_file: the #GKeyFile to retrieve the settings from
- * @group_name: the name of the group to use
- * @error: return location for errors, or %NULL
+ * @group_name: (allow-none): the name of the group to use, or %NULL to use the default
+ * "Print Settings"
+ * @error: (allow-none): return location for errors, or %NULL
*
- * Reads the print settings from the group @group_name in @key_file.
+ * Reads the print settings from the group @group_name in @key_file. If the
+ * file could not be loaded then error is set to either a #GFileError or
+ * #GKeyFileError.
*
* Return value: %TRUE on success
*
gchar *value;
value = g_key_file_get_string (key_file,
- KEYFILE_GROUP_NAME,
+ group_name,
keys[i],
NULL);
if (!value)
/**
* gtk_print_settings_new_from_key_file:
* @key_file: the #GKeyFile to retrieve the settings from
- * @group_name: the name of the group to use
- * @error: return location for errors, or %NULL
+ * @group_name: (allow-none): the name of the group to use, or %NULL to use
+ * the default "Print Settings"
+ * @error: (allow-none): return location for errors, or %NULL
*
- * Reads the print settings from the group @group_name in @key_file.
- * Returns a new #GtkPrintSettings object with the restored settings,
- * or %NULL if an error occurred.
+ * Reads the print settings from the group @group_name in @key_file. Returns a
+ * new #GtkPrintSettings object with the restored settings, or %NULL if an
+ * error occurred. If the file could not be loaded then error is set to either
+ * a #GFileError or #GKeyFileError.
*
* Return value: the restored #GtkPrintSettings
*
/**
* gtk_print_settings_to_file:
* @settings: a #GtkPrintSettings
- * @file_name: the file to save to
- * @error: return location for errors, or %NULL
+ * @file_name: (type filename): the file to save to
+ * @error: (allow-none): return location for errors, or %NULL
*
- * This function saves the print settings from @settings to @file_name.
+ * This function saves the print settings from @settings to @file_name. If the
+ * file could not be loaded then error is set to either a #GFileError or
+ * #GKeyFileError.
*
* Return value: %TRUE on success
*
(GtkPrintSettingsFunc) add_value_to_key_file,
&data);
}
-
-
-#define __GTK_PRINT_SETTINGS_C__
-#include "gtkaliasdef.c"