~ubuntu-branches/ubuntu/precise/tickr/precise-backports

« back to all changes in this revision

Viewing changes to src/tickr/news_clock.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Thomas-Maurin
  • Date: 2011-12-18 00:21:23 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111218002123-6h12joajjpatt170
Tags: 0.5.5-1
* Implement new parameter: <mouse wheel scrolling apply to:
* s = ticker-speed / f = feed-in-list / n = none>.

* Set <ticker pause on mouse-over> as optional.

* Select/highlight and scroll to added URL in the list window.

* Split compute_surface_and_win() code into compute_surface and
  compute_win, because the later is not always necessary. When
  window-always-on-top is disabled, compute_win needs to be run only
  twice at program startup (ie once after gtk_widget_show_all() has been
  called), then whenever params are changed, but not every time a new
  feed is loaded.

* Add preferences (settings) importing/exporting feature.

* 'file' scheme support added in tickr_http.c -> enables reading *and*
  xml-processing of (local) text files (wheras 'open text file' *only*
  read them.)

* 'HTTPS not supported' handling/warning added in tickr_http.c (fix bug:
  program freezes whith HTTP redirects to HTTPS.)

* xml 'quick check' in tickr_http.c:format_quick_check() don't reject
  anymore valid (?) feeds not starting with '<?xml' (like google news.)

* A few little changes in libetm-0.4 -> libetm-0.4.2.

* Use mouse wheel to go to previous/next feed.

* Hide passwords in connection settings window.

* Pause ticker and show feed title in tooltip on mouse-over.

* Renaming all source files: news_*.c/h -> tickr_*/c/h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *      TICKR - GTK-based Feed Reader - Copyright (C) Emmanuel Thomas-Maurin 2009-2011
3
 
 *      <manutm007@gmail.com>
4
 
 *
5
 
 *      This program is free software: you can redistribute it and/or modify
6
 
 *      it under the terms of the GNU General Public License as published by
7
 
 *      the Free Software Foundation, either version 3 of the License, or
8
 
 *      (at your option) any later version.
9
 
 *
10
 
 *      This program is distributed in the hope that it will be useful,
11
 
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *      GNU General Public License for more details.
14
 
 *
15
 
 *      You should have received a copy of the GNU General Public License
16
 
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include "news.h"
20
 
 
21
 
#ifdef G_OS_WIN32
22
 
extern FILE     *stdout_fp, *stderr_fp;
23
 
#endif
24
 
 
25
 
#define TIME_STR                "|%c%c:%c%c:%c%c"       /* at right = "|00:00:00" */
26
 
#define TIME_STR_LENGTH         9
27
 
 
28
 
void display_time(const Params *prm)
29
 
{
30
 
        TickerEnv               *env = get_ticker_env();
31
 
        PangoLayout             *p_layout;
32
 
        PangoFontDescription    *f_des;
33
 
        int                     layout_width, layout_height;
34
 
        cairo_surface_t         *surf_clock;
35
 
        cairo_t                 *cr;
36
 
        float                   shadow_k;
37
 
        char                    tmp[64];
38
 
        time_t                  time2;
39
 
        gint                    h_diff;
40
 
 
41
 
        if (prm->clock == 'l' || prm->clock == 'r') {
42
 
                if ((p_layout = pango_layout_new(gtk_widget_get_pango_context(env->win))) == NULL)
43
 
                        return;
44
 
                pango_layout_set_attributes(p_layout, NULL);
45
 
                pango_layout_set_single_paragraph_mode(p_layout, TRUE);
46
 
                f_des = pango_font_description_from_string((const char *)prm->clock_font_n_s);
47
 
                pango_layout_set_font_description(p_layout, f_des);
48
 
                pango_font_description_free(f_des);
49
 
 
50
 
                time2 = time(NULL);
51
 
                if (prm->clock == 'l') {
52
 
                        str_n_cpy(tmp, ctime(&time2) + 11, 8);
53
 
                        str_n_cat(tmp, "|", 1);
54
 
                } else if (prm->clock == 'r') {
55
 
                        str_n_cpy(tmp, "|", 1);
56
 
                        str_n_cat(tmp, ctime(&time2) + 11, 8);
57
 
                }
58
 
 
59
 
                pango_layout_set_text(p_layout, tmp, -1);
60
 
                pango_layout_context_changed(p_layout);
61
 
                pango_layout_get_pixel_size2(p_layout, &layout_width, &layout_height);
62
 
 
63
 
                env->drwa_clock_width = get_clock_width(prm);   /* v_diff */
64
 
                /*
65
 
                 * for some fonts like 'impact bold' which give strange things
66
 
                 * v_diff = drwa_clock_width - layout_width;
67
 
                 */
68
 
                gtk_widget_set_size_request(env->drwa_clock, env->drwa_clock_width, env->drwa_height);
69
 
                h_diff = (env->drwa_height - (gint)layout_height) / 2;
70
 
                /*
71
 
                 * create cairo image surface onto which layout will be rendered
72
 
                 */
73
 
                surf_clock = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
74
 
                        env->drwa_clock_width, env->drwa_height);
75
 
                cr = cairo_create(surf_clock);
76
 
                /*
77
 
                 * render layout
78
 
                 * (are used cairo operators ok ?)
79
 
                 */
80
 
                /* draw background */
81
 
                cairo_set_source_rgba(cr,
82
 
                        (float)prm->clock_bg_color.red / G_MAXUINT16,
83
 
                        (float)prm->clock_bg_color.green / G_MAXUINT16,
84
 
                        (float)prm->clock_bg_color.blue / G_MAXUINT16,
85
 
                        (float)prm->clock_bg_color_alpha / G_MAXUINT16
86
 
                        );
87
 
                cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
88
 
                cairo_paint(cr);
89
 
                /* draw foreground */
90
 
                if (prm->shadow == 'y') {
91
 
                        /* draw shadow */
92
 
                        if (prm->shadow_fx < 0)
93
 
                                shadow_k = 1.0;
94
 
                        else if (prm->shadow_fx > 10)
95
 
                                shadow_k = 0.0;
96
 
                        else
97
 
                                shadow_k = 1.0 - (float)prm->shadow_fx / 10.0;
98
 
                        cairo_set_source_rgba(cr,
99
 
                                (float)prm->clock_bg_color.red * shadow_k / G_MAXUINT16,
100
 
                                (float)prm->clock_bg_color.green * shadow_k / G_MAXUINT16,
101
 
                                (float)prm->clock_bg_color.blue * shadow_k / G_MAXUINT16,
102
 
                                (float)prm->clock_bg_color_alpha * shadow_k / G_MAXUINT16);
103
 
                        pango_cairo_update_layout(cr, p_layout);
104
 
                        cairo_move_to(cr, prm->shadow_offset_x, prm->shadow_offset_y);
105
 
                        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
106
 
                        pango_cairo_show_layout(cr, p_layout);
107
 
                }
108
 
                /* draw text */
109
 
                cairo_set_source_rgba(cr,
110
 
                        (float)prm->clock_fg_color.red / G_MAXUINT16,
111
 
                        (float)prm->clock_fg_color.green / G_MAXUINT16,
112
 
                        (float)prm->clock_fg_color.blue / G_MAXUINT16,
113
 
                        (float)prm->clock_fg_color_alpha / G_MAXUINT16);
114
 
                pango_cairo_update_layout(cr, p_layout);
115
 
                cairo_move_to(cr, 0, 0);
116
 
                cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
117
 
                pango_cairo_show_layout(cr, p_layout);
118
 
                /* drawing done */
119
 
                if (p_layout != NULL)
120
 
                        g_object_unref(p_layout);
121
 
                cairo_destroy(cr);
122
 
                /* draw onto clock area
123
 
                 * (we now use cairo instead of deprecated gdk_draw_sth)
124
 
                 */
125
 
                cr = gdk_cairo_create(GDK_DRAWABLE((env->drwa_clock)->window));
126
 
                cairo_set_source_surface(cr, surf_clock, 0, h_diff);
127
 
                cairo_rectangle(cr, 0, 0, env->drwa_clock_width, env->drwa_height);
128
 
                cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
129
 
                cairo_fill(cr);
130
 
                cairo_destroy(cr);
131
 
                cairo_surface_destroy(surf_clock);
132
 
        }
133
 
}
134
 
 
135
 
/* actually clock max width */
136
 
gint get_clock_width(const Params *prm)
137
 
{
138
 
        static char             clock_font_n_s_bak[FONT_MAXLEN + 1] = "";
139
 
        static gint             width = 0;
140
 
        PangoLayout             *p_layout;
141
 
        PangoFontDescription    *f_des;
142
 
        int                     layout_width, layout_height, layout_max_width = 0;
143
 
        char                    tmp[64];
144
 
        int                     i;
145
 
 
146
 
        if (prm->clock == 'l' || prm->clock == 'r') {
147
 
                if (strcmp(prm->clock_font_n_s, clock_font_n_s_bak) != 0 || width == 0) {
148
 
                        str_n_cpy(clock_font_n_s_bak, prm->clock_font_n_s, FONT_MAXLEN);
149
 
 
150
 
                        p_layout = pango_layout_new(gtk_widget_get_pango_context(get_ticker_env()->win));
151
 
                        pango_layout_set_attributes(p_layout, NULL);
152
 
                        pango_layout_set_single_paragraph_mode(p_layout, TRUE);
153
 
                        f_des = pango_font_description_from_string((const char *)prm->clock_font_n_s);
154
 
                        pango_layout_set_font_description(p_layout, f_des);
155
 
                        pango_font_description_free(f_des);
156
 
 
157
 
                        for (i = '0'; i <= '9'; i++) {
158
 
                                snprintf(tmp, TIME_STR_LENGTH + 1, TIME_STR, i, i, i, i, i, i);
159
 
                                pango_layout_set_text(p_layout, tmp, -1);
160
 
                                pango_layout_context_changed(p_layout);
161
 
                                pango_layout_get_pixel_size2(p_layout, &layout_width, &layout_height);
162
 
                                if (layout_width > layout_max_width)
163
 
                                        layout_max_width = layout_width;
164
 
                        }
165
 
 
166
 
                        if (p_layout != NULL)
167
 
                                g_object_unref(p_layout);
168
 
                        width = (gint)layout_max_width;
169
 
                }
170
 
        } else
171
 
                width = 0;      /* return 0 although if clock = none, actual widget width = 1 */
172
 
        return width;
173
 
}