~cairo-dock-team/ubuntu/oneiric/cairo-dock/2.3.0-3

« back to all changes in this revision

Viewing changes to src/gldit/cairo-dock-internal-labels.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20100809232612-pocdxliaxjdetm37
Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#include <string.h>
 
21
 
 
22
#include "cairo-dock-modules.h"
 
23
#include "cairo-dock-load.h"
 
24
#include "cairo-dock-config.h"
 
25
#include "cairo-dock-draw.h"
 
26
#include "cairo-dock-dock-factory.h"
 
27
#include "cairo-dock-dock-facility.h"
 
28
#include "cairo-dock-dock-manager.h"
 
29
#include "cairo-dock-internal-icons.h"
 
30
#include "cairo-dock-container.h"
 
31
#define _INTERNAL_MODULE_
 
32
#include "cairo-dock-internal-labels.h"
 
33
 
 
34
CairoConfigLabels myLabels;
 
35
 
 
36
static gboolean get_config (GKeyFile *pKeyFile, CairoConfigLabels *pLabels)
 
37
{
 
38
        gboolean bFlushConfFileNeeded = FALSE;
 
39
        
 
40
        gboolean bCustomFont = cairo_dock_get_boolean_key_value (pKeyFile, "Labels", "custom", &bFlushConfFileNeeded, TRUE, NULL, NULL);
 
41
        
 
42
        gchar *cFontDescription = (bCustomFont ? cairo_dock_get_string_key_value (pKeyFile, "Labels", "police", &bFlushConfFileNeeded, NULL, "Icons", NULL) : NULL);
 
43
        if (cFontDescription == NULL)
 
44
                cFontDescription = cairo_dock_get_default_system_font ();
 
45
        
 
46
        PangoFontDescription *fd = pango_font_description_from_string (cFontDescription);
 
47
        pLabels->iconTextDescription.cFont = g_strdup (pango_font_description_get_family (fd));
 
48
        pLabels->iconTextDescription.iSize = pango_font_description_get_size (fd);
 
49
        if (!pango_font_description_get_size_is_absolute (fd))
 
50
                pLabels->iconTextDescription.iSize /= PANGO_SCALE;
 
51
        if (!bCustomFont)
 
52
                pLabels->iconTextDescription.iSize *= 1.33;  // c'est pas beau, mais ca evite de casser tous les themes.
 
53
        if (pLabels->iconTextDescription.iSize == 0)
 
54
                pLabels->iconTextDescription.iSize = 14;
 
55
        pLabels->iconTextDescription.iWeight = pango_font_description_get_weight (fd);
 
56
        pLabels->iconTextDescription.iStyle = pango_font_description_get_style (fd);
 
57
        
 
58
        if (g_key_file_has_key (pKeyFile, "Labels", "size", NULL))  // anciens parametres.
 
59
        {
 
60
                pLabels->iconTextDescription.iSize = g_key_file_get_integer (pKeyFile, "Labels", "size", NULL);
 
61
                int iLabelWeight = g_key_file_get_integer (pKeyFile, "Labels", "weight", NULL);
 
62
                pLabels->iconTextDescription.iWeight = cairo_dock_get_pango_weight_from_1_9 (iLabelWeight);
 
63
                gboolean bLabelStyleItalic = g_key_file_get_boolean (pKeyFile, "Labels", "italic", NULL);
 
64
                if (bLabelStyleItalic)
 
65
                        pLabels->iconTextDescription.iStyle = PANGO_STYLE_ITALIC;
 
66
                else
 
67
                        pLabels->iconTextDescription.iStyle = PANGO_STYLE_NORMAL;
 
68
                
 
69
                pango_font_description_set_size (fd, pLabels->iconTextDescription.iSize * PANGO_SCALE);
 
70
                pango_font_description_set_weight (fd, pLabels->iconTextDescription.iWeight);
 
71
                pango_font_description_set_style (fd, pLabels->iconTextDescription.iStyle);
 
72
                
 
73
                g_free (cFontDescription);
 
74
                cFontDescription = pango_font_description_to_string (fd);
 
75
                g_key_file_set_string (pKeyFile, "Labels", "police", cFontDescription);
 
76
                bFlushConfFileNeeded = TRUE;
 
77
        }
 
78
        pango_font_description_free (fd);
 
79
        g_free (cFontDescription);
 
80
        
 
81
        int iShowLabel = cairo_dock_get_integer_key_value (pKeyFile, "Labels", "show_labels", &bFlushConfFileNeeded, -1, NULL, NULL);
 
82
        gboolean bShow, bLabelForPointedIconOnly;
 
83
        if (iShowLabel == -1)  // nouveau parametre
 
84
        {
 
85
                if (g_key_file_has_key (pKeyFile, "Labels", "show labels", NULL))
 
86
                        bShow = g_key_file_get_boolean (pKeyFile, "Labels", "show labels", NULL);
 
87
                else
 
88
                        bShow = TRUE;
 
89
                bLabelForPointedIconOnly = g_key_file_get_boolean (pKeyFile, "System", "pointed icon only", NULL);
 
90
                iShowLabel = (! bShow ? 0 : (bLabelForPointedIconOnly ? 1 : 2));
 
91
                g_key_file_set_integer (pKeyFile, "Labels", "show_labels", iShowLabel);
 
92
        }
 
93
        else
 
94
        {
 
95
                bShow = (iShowLabel != 0);
 
96
                bLabelForPointedIconOnly = (iShowLabel == 1);
 
97
        }
 
98
        //g_print ("labels : %d;%d\n", bShow, bLabelForPointedIconOnly);
 
99
        if (! bShow)
 
100
        {
 
101
                g_free (pLabels->iconTextDescription.cFont);
 
102
                pLabels->iconTextDescription.cFont = NULL;
 
103
                pLabels->iconTextDescription.iSize = 0;
 
104
        }
 
105
        pLabels->bLabelForPointedIconOnly = bLabelForPointedIconOnly;
 
106
        
 
107
        pLabels->iconTextDescription.bOutlined = cairo_dock_get_boolean_key_value (pKeyFile, "Labels", "text oulined", &bFlushConfFileNeeded, TRUE, NULL, NULL);
 
108
        
 
109
        double couleur_label[3] = {1., 1., 1.};
 
110
        cairo_dock_get_double_list_key_value (pKeyFile, "Labels", "text color start", &bFlushConfFileNeeded, pLabels->iconTextDescription.fColorStart, 3, couleur_label, "Icons", NULL);
 
111
        
 
112
        cairo_dock_get_double_list_key_value (pKeyFile, "Labels", "text color stop", &bFlushConfFileNeeded, pLabels->iconTextDescription.fColorStop, 3, couleur_label, "Icons", NULL);
 
113
        
 
114
        pLabels->iconTextDescription.bVerticalPattern = cairo_dock_get_boolean_key_value (pKeyFile, "Labels", "vertical label pattern", &bFlushConfFileNeeded, TRUE, "Icons", NULL);
 
115
 
 
116
        double couleur_backlabel[4] = {0., 0., 0., 0.5};
 
117
        cairo_dock_get_double_list_key_value (pKeyFile, "Labels", "text background color", &bFlushConfFileNeeded, pLabels->iconTextDescription.fBackgroundColor, 4, couleur_backlabel, "Icons", NULL);
 
118
        
 
119
        pLabels->iconTextDescription.iMargin = cairo_dock_get_integer_key_value (pKeyFile, "Labels", "text margin", &bFlushConfFileNeeded, 4, NULL, NULL);
 
120
        
 
121
        memcpy (&pLabels->quickInfoTextDescription, &pLabels->iconTextDescription, sizeof (CairoDockLabelDescription));
 
122
        pLabels->quickInfoTextDescription.cFont = g_strdup (pLabels->iconTextDescription.cFont);
 
123
        pLabels->quickInfoTextDescription.iSize = 12;
 
124
        pLabels->quickInfoTextDescription.iWeight = PANGO_WEIGHT_HEAVY;
 
125
        pLabels->quickInfoTextDescription.iStyle = PANGO_STYLE_NORMAL;
 
126
        
 
127
        gboolean bUseBackgroundForLabel = cairo_dock_get_boolean_key_value (pKeyFile, "Labels", "background for label", &bFlushConfFileNeeded, FALSE, "Icons", NULL);
 
128
        if (! bUseBackgroundForLabel)
 
129
                pLabels->iconTextDescription.fBackgroundColor[3] = 0;  // ne sera pas dessine.
 
130
        
 
131
        pLabels->iLabelSize = (pLabels->iconTextDescription.iSize != 0 ?
 
132
                pLabels->iconTextDescription.iSize +
 
133
                (pLabels->iconTextDescription.bOutlined ? 2 : 0) +
 
134
                2 * pLabels->iconTextDescription.iMargin : 0);
 
135
        
 
136
        return bFlushConfFileNeeded;
 
137
}
 
138
 
 
139
 
 
140
static void reset_config (CairoConfigLabels *pLabels)
 
141
{
 
142
        g_free (pLabels->iconTextDescription.cFont);
 
143
        g_free (pLabels->quickInfoTextDescription.cFont);
 
144
}
 
145
 
 
146
 
 
147
static void _reload_one_label (Icon *pIcon, CairoContainer *pContainer, CairoConfigLabels *pLabels)
 
148
{
 
149
        cairo_dock_load_icon_text (pIcon, &pLabels->iconTextDescription);
 
150
        double fMaxScale = cairo_dock_get_max_scale (pContainer);
 
151
        cairo_dock_load_icon_quickinfo (pIcon, &pLabels->quickInfoTextDescription, fMaxScale);
 
152
}
 
153
static void _cairo_dock_resize_one_dock (gchar *cDockName, CairoDock *pDock, gpointer data)
 
154
{
 
155
        cairo_dock_update_dock_size (pDock);
 
156
}
 
157
static void reload (CairoConfigLabels *pPrevLabels, CairoConfigLabels *pLabels)
 
158
{
 
159
        cairo_dock_foreach_icons ((CairoDockForeachIconFunc) _reload_one_label, pLabels);
 
160
        
 
161
        if (pPrevLabels->iLabelSize != pLabels->iLabelSize)
 
162
        {
 
163
                cairo_dock_foreach_docks ((GHFunc) _cairo_dock_resize_one_dock, NULL);
 
164
        }
 
165
}
 
166
 
 
167
 
 
168
DEFINE_PRE_INIT (Labels)
 
169
{
 
170
        pModule->cModuleName = "Labels";
 
171
        pModule->cTitle = N_("Captions");
 
172
        pModule->cIcon = "icon-labels.svg";
 
173
        pModule->cDescription = N_("Define icon caption and quick-info style.");
 
174
        pModule->iCategory = CAIRO_DOCK_CATEGORY_THEME;
 
175
        pModule->iSizeOfConfig = sizeof (CairoConfigLabels);
 
176
        pModule->iSizeOfData = 0;
 
177
        
 
178
        pModule->reload = (CairoDockInternalModuleReloadFunc) reload;
 
179
        pModule->get_config = (CairoDockInternalModuleGetConfigFunc) get_config;
 
180
        pModule->reset_config = (CairoDockInternalModuleResetConfigFunc) reset_config;
 
181
        pModule->reset_data = NULL;
 
182
        
 
183
        pModule->pConfig = (CairoInternalModuleConfigPtr) &myLabels;
 
184
        pModule->pData = NULL;
 
185
}