~ubuntu-branches/ubuntu/hoary/zenity/hoary

« back to all changes in this revision

Viewing changes to src/msg.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-03-07 17:03:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050307170331-j0667q5o1ni6308d
Tags: upstream-2.10.0
ImportĀ upstreamĀ versionĀ 2.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * msg.c
 
3
 *
 
4
 * Copyright (C) 2002 Sun Microsystems, Inc.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this library; if not, write to the
 
18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
 * Boston, MA 02111-1307, USA.
 
20
 *
 
21
 * Authors: Glynn Foster <glynn.foster@sun.com>
 
22
 */
 
23
 
 
24
#include <glade/glade.h>
 
25
#include "zenity.h"
 
26
#include "util.h"
 
27
 
 
28
static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data);
 
29
 
 
30
void 
 
31
zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
 
32
{
 
33
  GladeXML *glade_dialog;
 
34
  GtkWidget *dialog;
 
35
  GtkWidget *text;
 
36
 
 
37
  switch (msg_data->mode) {
 
38
    case ZENITY_MSG_WARNING:
 
39
      glade_dialog = zenity_util_load_glade_file ("zenity_warning_dialog");
 
40
      dialog = glade_xml_get_widget (glade_dialog, "zenity_warning_dialog");
 
41
      text = glade_xml_get_widget (glade_dialog, "zenity_warning_text");
 
42
      break;
 
43
 
 
44
    case ZENITY_MSG_QUESTION:
 
45
      glade_dialog = zenity_util_load_glade_file ("zenity_question_dialog");
 
46
      dialog = glade_xml_get_widget (glade_dialog, "zenity_question_dialog");
 
47
      text = glade_xml_get_widget (glade_dialog, "zenity_question_text");
 
48
      break;
 
49
 
 
50
    case ZENITY_MSG_ERROR:
 
51
      glade_dialog = zenity_util_load_glade_file ("zenity_error_dialog");
 
52
      dialog = glade_xml_get_widget (glade_dialog, "zenity_error_dialog");
 
53
      text = glade_xml_get_widget (glade_dialog, "zenity_error_text");
 
54
      break;
 
55
 
 
56
    case ZENITY_MSG_INFO:
 
57
      glade_dialog = zenity_util_load_glade_file ("zenity_info_dialog");
 
58
      dialog= glade_xml_get_widget (glade_dialog, "zenity_info_dialog");
 
59
      text = glade_xml_get_widget (glade_dialog, "zenity_info_text");
 
60
      break;
 
61
                
 
62
    default:
 
63
      glade_dialog = NULL;
 
64
      dialog = NULL;
 
65
      text = NULL;
 
66
      g_assert_not_reached ();
 
67
      break;    
 
68
  }
 
69
 
 
70
  g_signal_connect (G_OBJECT (dialog), "response",
 
71
                    G_CALLBACK (zenity_msg_dialog_response), data);
 
72
        
 
73
  if (glade_dialog == NULL) {
 
74
    data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
 
75
    return;
 
76
  }
 
77
        
 
78
  glade_xml_signal_autoconnect (glade_dialog);
 
79
        
 
80
  if (glade_dialog)
 
81
    g_object_unref (glade_dialog);
 
82
 
 
83
  if (data->dialog_title)
 
84
    gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
 
85
 
 
86
  switch (msg_data->mode) {
 
87
    case ZENITY_MSG_WARNING:
 
88
      zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_WARNING);
 
89
      break;
 
90
 
 
91
    case ZENITY_MSG_QUESTION:
 
92
      zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_QUESTION);
 
93
      break;
 
94
      
 
95
    case ZENITY_MSG_ERROR:
 
96
      zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_ERROR);
 
97
      break;
 
98
      
 
99
    case ZENITY_MSG_INFO:
 
100
      zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_INFO);
 
101
      break;
 
102
  
 
103
    default:
 
104
      break;
 
105
  }
 
106
  
 
107
  if (data->width > -1 || data->height > -1)
 
108
    gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
 
109
        
 
110
  if (msg_data->dialog_text)
 
111
    gtk_label_set_markup (GTK_LABEL (text), msg_data->dialog_text);
 
112
 
 
113
  zenity_util_show_dialog (dialog);
 
114
  gtk_main ();
 
115
}
 
116
 
 
117
static void
 
118
zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
 
119
{
 
120
  ZenityData *zen_data = data;
 
121
 
 
122
  switch (response) {
 
123
    case GTK_RESPONSE_OK:
 
124
      zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
 
125
      break;
 
126
 
 
127
    case GTK_RESPONSE_CANCEL:
 
128
      zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL);
 
129
      break;
 
130
 
 
131
    default:
 
132
      zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
 
133
      break;
 
134
  }
 
135
  gtk_main_quit ();
 
136
}