~ubuntu-branches/ubuntu/natty/gnome-chemistry-utils/natty-security

« back to all changes in this revision

Viewing changes to programs/crystal/prefs.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha
  • Date: 2007-12-12 20:34:25 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071212203425-yfb4zry8fdy8iupn
Tags: 0.8.4-3ubuntu1
* Merge from Debian unstable
* debian/control: add firefox to gcu-plugin dependencies
* Modify Maintainer value to match the DebianMaintainerField
  specification.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- C++ -*-
 
2
 
 
3
/* 
 
4
 * Gnome Crystal
 
5
 * prefs.cc 
 
6
 *
 
7
 * Copyright (C) 2001-2007 Jean Bréfort <jean.brefort@normalesup.org>
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or 
 
10
 * modify it under the terms of the GNU General Public License as 
 
11
 * published by the Free Software Foundation; either version 2 of the
 
12
 * License, or (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
22
 * USA
 
23
 */
 
24
 
 
25
#include "config.h"
 
26
#include "prefs.h"
 
27
#include "globals.h"
 
28
#include "application.h"
 
29
 
 
30
guint PrintResolution = 300;
 
31
 
 
32
static void on_print_resolution (GtkWidget *widget, gcPrefsDlg * dialog)
 
33
{
 
34
        dialog->UpdatePrinting ();
 
35
}
 
36
 
 
37
gcPrefsDlg::gcPrefsDlg (gcApplication *App): Dialog (App, GLADEDIR"/prefs.glade", "prefs", App)
 
38
{
 
39
        if (!xml) {
 
40
                delete this;
 
41
                return;
 
42
        }
 
43
        PrintResMenu = (GtkComboBox *) glade_xml_get_widget (xml, "printres");
 
44
        PrintResBtn = (GtkSpinButton *) glade_xml_get_widget (xml, "printresbtn");
 
45
        int PrintIndex;
 
46
        bool active = false;
 
47
        switch (PrintResolution) {
 
48
        case 300:
 
49
                PrintIndex = 0;
 
50
                break;
 
51
        case 360:
 
52
                PrintIndex = 1;
 
53
                break;
 
54
        case 600:
 
55
                PrintIndex = 2;
 
56
                break;
 
57
        case 720:
 
58
                PrintIndex = 3;
 
59
                break;
 
60
        case 1200:
 
61
                PrintIndex = 4;
 
62
                break;
 
63
        case 1440:
 
64
                PrintIndex = 5;
 
65
                break;
 
66
        case 2400:
 
67
                PrintIndex = 6;
 
68
                break;
 
69
        case 2880:
 
70
                PrintIndex = 7;
 
71
                break;
 
72
        default:
 
73
                PrintIndex = 8;
 
74
                active = true;
 
75
                break;
 
76
        }
 
77
        gtk_spin_button_set_value (PrintResBtn, PrintResolution);
 
78
        gtk_widget_set_sensitive (GTK_WIDGET (PrintResBtn), active);
 
79
        gtk_combo_box_set_active (PrintResMenu, PrintIndex);
 
80
        g_signal_connect (PrintResMenu, "changed", G_CALLBACK (on_print_resolution), this);
 
81
        FoVBtn = GTK_SPIN_BUTTON (glade_xml_get_widget (xml, "fov"));
 
82
        gtk_spin_button_set_value (FoVBtn, FoV);
 
83
        PsiEnt = (GtkEntry *) glade_xml_get_widget (xml, "psi");
 
84
        ThetaEnt = (GtkEntry *) glade_xml_get_widget (xml, "theta");
 
85
        PhiEnt = (GtkEntry *) glade_xml_get_widget (xml, "phi");
 
86
        char m_buf[32];
 
87
        snprintf (m_buf, sizeof (m_buf) - 1, "%g", Psi);
 
88
        gtk_entry_set_text (PsiEnt, m_buf);
 
89
        snprintf (m_buf, sizeof (m_buf) - 1, "%g", Theta);
 
90
        gtk_entry_set_text (ThetaEnt, m_buf);
 
91
        snprintf (m_buf, sizeof (m_buf) - 1, "%g", Phi);
 
92
        gtk_entry_set_text (PhiEnt, m_buf);
 
93
        BackgroundBtn = (GtkColorButton *) glade_xml_get_widget (xml, "color");
 
94
        GdkColor color;
 
95
        color.red = (guint16) (Red * 65535.);
 
96
        color.green = (guint16) (Green * 65535.);
 
97
        color.blue = (guint16) (Blue * 65535.);
 
98
        gtk_color_button_set_color (BackgroundBtn, &color);
 
99
        gtk_widget_show_all (GTK_WIDGET (dialog));
 
100
}
 
101
 
 
102
gcPrefsDlg::~gcPrefsDlg()
 
103
{
 
104
}
 
105
 
 
106
bool gcPrefsDlg::Apply()
 
107
{
 
108
        double x0, x1, x2;
 
109
        if (!GetNumber (PsiEnt, &x0, MinEqMax, -180, 180))
 
110
                return false;
 
111
        if (!GetNumber (ThetaEnt, &x1, MinEqMaxEq, 0, 180))
 
112
                return false;
 
113
        if (!GetNumber (PhiEnt, &x2, MinEqMax, -180, 180))
 
114
                return false;
 
115
        PrintResolution = gtk_spin_button_get_value_as_int (PrintResBtn);
 
116
        Psi = x0;
 
117
        Theta= x1;
 
118
        Phi = x2;
 
119
        FoV = gtk_spin_button_get_value_as_int(FoVBtn);
 
120
        GdkColor color;
 
121
        gtk_color_button_get_color (BackgroundBtn, &color);
 
122
        Red = color.red / 65535.;
 
123
        Green = color.green / 65535.;
 
124
        Blue = color.blue / 65535.;
 
125
        gconf_client_set_int (conf_client, "/apps/gcrystal/printing/resolution", PrintResolution, NULL);
 
126
        gconf_client_set_int (conf_client, "/apps/gcrystal/views/fov", FoV, NULL);
 
127
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/psi", Psi, NULL);
 
128
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/theta", Theta, NULL);
 
129
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/phi", Phi, NULL);
 
130
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/red", Red, NULL);
 
131
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/green", Green, NULL);
 
132
        gconf_client_set_float (conf_client, "/apps/gcrystal/views/blue", Blue, NULL);
 
133
        return true;
 
134
}
 
135
 
 
136
void gcPrefsDlg::UpdatePrinting ()
 
137
{
 
138
        int PrintRes = PrintResolution ;
 
139
        int PrintIndex = gtk_combo_box_get_active (PrintResMenu);
 
140
        switch (PrintIndex)
 
141
        {
 
142
        case 0:
 
143
                PrintRes = 300;
 
144
                break;
 
145
        case 1:
 
146
                PrintRes = 360;
 
147
                break;
 
148
        case 2:
 
149
                PrintRes = 600;
 
150
                break;
 
151
        case 3:
 
152
                PrintRes = 720;
 
153
                break;
 
154
        case 4:
 
155
                PrintRes = 1200;
 
156
                break;
 
157
        case 5:
 
158
                PrintRes = 1440;
 
159
                break;
 
160
        case 6:
 
161
                PrintRes = 2400;
 
162
                break;
 
163
        case 7:
 
164
                PrintRes = 2880;
 
165
                break;
 
166
        }
 
167
        gtk_spin_button_set_value (PrintResBtn, PrintRes);
 
168
        gtk_widget_set_sensitive (GTK_WIDGET (PrintResBtn), (PrintIndex < 8)? false : true);
 
169
}