:pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Fri Dec 14 20:46 CET 2001
[gnokii.git] / xgnokii / xgnokii_logos.c
1 /*
2
3   $Id$
4    
5   X G N O K I I
6
7   A Linux/Unix GUI for Nokia mobile phones.
8   Copyright (C) 1999 Pavel Janík ml., Hugh Blemings
9   & Ján Derfiòák <ja@mail.upjs.sk>.
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13 */
14           
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <fcntl.h>
18 #include <signal.h>
19 #include <sys/types.h>
20 #include <string.h>
21 #include <gtk/gtk.h>
22
23 #include "misc.h"
24 #include "gsm-common.h"
25 #include "gsm-api.h"
26 #include "cfgreader.h"
27 #include "gsm-networks.h"
28 #include "gsm-filetypes.h"
29 #include "gsm-bitmaps.h"
30
31 #include "xgnokii_logos.h"
32 #include "xgnokii_common.h"
33 #include "xgnokii_lowlevel.h"
34 #include "xgnokii.h"
35
36 #include "xpm/Operator_logo.xpm"
37 #include "xpm/Startup_logo.xpm"
38 #include "xpm/Caller_logo.xpm"
39
40 #include "xpm/Black_point.xpm"
41 #include "xpm/Green_point.xpm"
42 #include "xpm/Green_pixel.xpm"
43
44 #include "xpm/New.xpm"
45 #include "xpm/Send.xpm"
46 #include "xpm/Read.xpm"
47 #include "xpm/Open.xpm"
48 #include "xpm/Save.xpm"
49
50 #include "xpm/Edit_invert.xpm"
51 #include "xpm/Edit_flip_horizontal.xpm"
52 #include "xpm/Edit_flip_vertical.xpm"
53
54 #include "xpm/Tool_brush.xpm"
55 #include "xpm/Tool_line.xpm"
56 #include "xpm/Tool_rectangle.xpm"
57 #include "xpm/Tool_filled_rectangle.xpm"
58
59 extern GSM_Network GSM_Networks[];
60 extern GSM_Statemachine statemachine;
61
62 GtkWidget *GUI_LogosWindow;
63
64 ErrorDialog errorDialog = {NULL, NULL};
65 InfoDialog infoDialog = {NULL, NULL};
66
67 /* stuff for drawingArea */
68 GtkWidget *drawingArea = NULL;
69 GdkPixmap *drawingPixmap = NULL;
70 GdkPixmap *greenPointPixmap, *blackPointPixmap;
71 int drawingAreaWidth, drawingAreaHeight; /* in pixels */
72 int mouseButtonPushed = 0;
73
74 /* stuff for previewArea */
75 GtkWidget *previewArea = NULL;
76 GdkPixmap *previewPixmap = NULL;
77 GdkPixmap *greenPixelPixmap;
78 int previewPixmapWidth, previewPixmapHeight;
79 int previewAvailable = 1, showPreviewErrorDialog = 1;
80 int previewPixmapNumber = 0;
81
82 GSM_Bitmap bitmap, oldBitmap;
83 GSM_NetworkInfo networkInfo;
84
85 /* widgets for toolbar - some, need global variables */
86 GtkWidget *buttonStartup, *buttonOperator, *buttonCaller;
87 GtkWidget *networkCombo, *callerCombo;
88
89 int activeTool = TOOL_BRUSH;
90 int toolStartX, toolStartY, toolLastX, toolLastY;
91
92 /* tools for drawing */
93 static GtkWidget *buttonBrush, *buttonLine, *buttonRectangle;
94 static GtkWidget *buttonFilledRectangle;
95
96 /* Contains fileName for Export dialog. */
97 typedef struct {
98   gchar *fileName;
99 } ExportDialogData;
100
101 static ExportDialogData exportDialogData = {NULL};
102
103 GtkWidget *FileSelection;
104
105 static int callersGroupsInitialized = 0;
106
107 /* returns lowest number from three numbers */
108 int GetMinFrom3(int a, int b, int c) {
109   if (a > b) {
110     if (b > c)
111       return c;
112     else
113       return b;
114   } else {
115     if (a > c)
116       return c;
117     else
118       return a;    
119   }
120 }
121
122 /* returns highest number from three numbers */
123 int GetMaxFrom3(int a, int b, int c) {
124   if (a > b) {
125     if (c > a)
126       return c;
127     else
128       return a;
129   } else {
130     if (c > b)
131       return c;
132     else
133       return b;
134   }
135 }
136
137 /* load preview pixmap from file */
138 GdkPixmap *GetPreviewPixmap (GtkWidget *widget) {
139   GdkPixmap *pixmap;
140   GdkBitmap *mask;
141   gchar *file;
142
143   if (previewPixmapNumber == 0)
144   {
145     if (!strcmp (xgnokiiConfig.model, "6110") ||
146         !strcmp (xgnokiiConfig.model, "6120"))
147     {
148       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
149                              "/xpm/Preview_6110.xpm");
150       previewPixmapNumber = 1;
151     }
152     else if (!strcmp (xgnokiiConfig.model, "6130") ||
153              !strcmp (xgnokiiConfig.model, "6150") ||
154              !strcmp (xgnokiiConfig.model, "616x") ||
155              !strcmp (xgnokiiConfig.model, "6185") ||
156              !strcmp (xgnokiiConfig.model, "6190"))
157     {
158       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
159                              "/xpm/Preview_6150.xpm");
160       previewPixmapNumber = 2;
161     }
162     else if (!strcmp (xgnokiiConfig.model, "3210"))
163     {
164       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
165                              "/xpm/Preview_3210.xpm");
166       previewPixmapNumber = 3;
167     }
168     else if (!strcmp (xgnokiiConfig.model, "3310") ||
169              !strcmp (xgnokiiConfig.model, "3330"))
170     {
171       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
172                              "/xpm/Preview_3310.xpm");
173       previewPixmapNumber = 4;
174     }
175     else if (!strcmp (xgnokiiConfig.model, "5110") ||
176              !strcmp (xgnokiiConfig.model, "5130"))
177     {
178       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
179                              "/xpm/Preview_5110.xpm");
180       previewPixmapNumber = 5;
181     }
182     else if (!strcmp (xgnokiiConfig.model, "6250"))
183     {
184       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
185                              "/xpm/Preview_6250.xpm");
186       previewPixmapNumber = 6;
187     }
188     else if (!strcmp (xgnokiiConfig.model, "7110"))
189     {
190       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
191                              "/xpm/Preview_7110.xpm");
192       previewPixmapNumber = 7;
193     }
194     else
195     {
196       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
197                              "/xpm/Preview_6210.xpm");
198       previewPixmapNumber = 8;
199     }
200   }
201   else
202     switch (previewPixmapNumber)
203     {
204       case 1: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
205                                      "/xpm/Preview_6110.xpm"); 
206               break;
207       case 2: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
208                                      "/xpm/Preview_6150.xpm"); 
209               break;
210       case 3: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
211                                      "/xpm/Preview_3210.xpm"); 
212               break;
213       case 4: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
214                                      "/xpm/Preview_3310.xpm"); 
215               break;
216       case 5: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
217                                      "/xpm/Preview_5110.xpm"); 
218               break;
219       case 6: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
220                                      "/xpm/Preview_6250.xpm"); 
221               break;
222       case 7: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
223                                      "/xpm/Preview_7110.xpm"); 
224               break;
225       default: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
226                                       "/xpm/Preview_6210.xpm");
227               break;
228     }
229
230   pixmap = gdk_pixmap_create_from_xpm(widget->window,&mask,
231                                       &widget->style->bg[GTK_STATE_NORMAL],
232                                       file);
233
234   g_free(file);
235
236   return pixmap;
237 }
238
239 /* ********************************************************
240  * ** SET/CLEAR POINTS ************************************
241  * ********************************************************
242  */
243 void SetPreviewPoint(GtkWidget *widget, int x, int y, int update) {
244   if (!previewAvailable) return;
245   
246   /* there is difference between positiong of startupLogo and others */
247   if (bitmap.type != GSM_StartupLogo) {
248     x += PREVIEWJUMPX;
249     y += PREVIEWJUMPY;
250   }
251
252   /* draw point to pixmap */
253   if (previewPixmap)
254     gdk_draw_point(previewPixmap,widget->style->black_gc,
255                    x+PREVIEWSTARTX,y+PREVIEWSTARTY);
256
257   if (update) {
258     GdkRectangle updateRect;
259
260     /* update point on screen */
261     updateRect.width = 1;
262     updateRect.height = 1;
263     updateRect.x = PREVIEWSTARTX+x;
264     updateRect.y = PREVIEWSTARTY+y;
265
266     gtk_widget_draw(previewArea,&updateRect);
267   }  
268 }
269
270 void ClearPreviewPoint(GtkWidget *widget, int x, int y, int update) {
271   if (!previewAvailable) return;
272   
273   /* there is difference between positiong of startupLogo and others */
274   if (bitmap.type != GSM_StartupLogo) {
275     x += PREVIEWJUMPX;
276     y += PREVIEWJUMPY;
277   }
278
279   /* clean point from pixmap - any idea how to draw green point without pixmap? */
280   if (previewPixmap)
281     gdk_draw_pixmap(previewPixmap,
282                     widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
283                     greenPixelPixmap,0,0,x+PREVIEWSTARTX,y+PREVIEWSTARTY,1,1);
284   if (update) {
285     GdkRectangle updateRect;
286
287     /* clean from screen too */
288     updateRect.width = 1;
289     updateRect.height = 1;
290     updateRect.x = PREVIEWSTARTX+x;
291     updateRect.y = PREVIEWSTARTY+y;
292
293     gtk_widget_draw(previewArea,&updateRect);
294   }
295 }
296
297 int IsPoint(int x, int y) {
298   return GSM_IsPointBitmap(&bitmap,x,y);
299 }
300
301 void SetPoint(GtkWidget *widget, int x, int y, int update) {
302   /* difference between settings points in startupLogo and others */
303   GSM_SetPointBitmap(&bitmap,x,y);
304
305   /* draw point to pixmap */
306   gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
307           blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
308
309   if (update) {
310     GdkRectangle updateRect;
311
312     /* calculate update rectangle */
313     updateRect.width = POINTSIZE+2;
314     updateRect.height = POINTSIZE+2;
315     updateRect.x = x * (POINTSIZE+1);
316     updateRect.y = y * (POINTSIZE+1);
317
318     /* update on screen */
319     gtk_widget_draw(drawingArea,&updateRect);
320   }
321
322   /* draw preview point too */
323   if (previewAvailable) SetPreviewPoint(widget,x,y,update); 
324 }
325
326 void ClearPoint(GtkWidget *widget, int x, int y, int update) {
327   /* difference between settings points in startupLogo and others */
328   GSM_ClearPointBitmap(&bitmap,x,y);
329
330   /* clear point from pixmap */
331   gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
332           greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
333
334   if (update) {
335     GdkRectangle updateRect;
336
337     /* calculate update rectangle */
338     updateRect.width = POINTSIZE+2;
339     updateRect.height = POINTSIZE+2;
340     updateRect.x = x * (POINTSIZE+1);
341     updateRect.y = y * (POINTSIZE+1);
342           
343     /* update on screen */
344     gtk_widget_draw(drawingArea,&updateRect);
345   }
346
347   /* clear point from previewArea too */
348   if (previewAvailable) ClearPreviewPoint(widget,x,y,update); 
349 }
350
351 /* ****************************************************
352  * *** UPDATES - PREVIEW & DRAWING AREAS **************
353  * ****************************************************
354  */
355
356 /* this redraw all logo points - preview & drawing area */
357 void UpdatePointsRectangle(GtkWidget *widget, int x1, int y1, int x2, int y2) {
358   GdkRectangle updateRect;
359   int x, y, dx = 0, dy = 0;
360
361   if (bitmap.type != GSM_StartupLogo) {
362     dx = PREVIEWJUMPX;
363     dy = PREVIEWJUMPY;
364   }
365
366   if (x1 > x2) {
367     x = x1;
368     x1 = x2;
369     x2 = x;
370   }
371
372   if (y1 > y2) {
373     y = y1;
374     y1 = y2;
375     y2 = y;
376   }
377   
378   for (y = y1;y <= y2;y++)
379     for (x = x1;x <= x2;x++) {
380       if (IsPoint(x,y)) {
381         /* set on drawing area */
382         gdk_draw_pixmap(drawingPixmap,
383                         drawingArea->style->fg_gc[GTK_WIDGET_STATE(drawingArea)],
384                         blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
385
386         /* set on preview */
387         if (previewAvailable && previewPixmap) 
388           gdk_draw_point(previewPixmap,previewArea->style->black_gc,
389                          x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy);
390       } else {
391         /* clear from drawing */
392         gdk_draw_pixmap(drawingPixmap,
393                         drawingArea->style->fg_gc[GTK_WIDGET_STATE(drawingArea)],
394                         greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
395
396         /* clear from preview */
397         if (previewAvailable && previewPixmap) 
398           gdk_draw_pixmap(previewPixmap,
399                           previewArea->style->fg_gc[GTK_WIDGET_STATE(previewArea)],
400                           greenPixelPixmap,0,0,x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy,
401                           1,1);
402       }
403     }
404      
405   if (previewAvailable) {  
406     updateRect.x = PREVIEWSTARTX+dx+x1;
407     updateRect.y = PREVIEWSTARTY+dy+y1;
408     updateRect.width = x2-x1+1;
409     updateRect.height = y2-y1+1;
410     gtk_widget_draw(previewArea,&updateRect);
411   }  
412
413   updateRect.x = x1*(POINTSIZE+1);
414   updateRect.y = y1*(POINTSIZE+1);
415   updateRect.width = (x2-x1+1)*(POINTSIZE+1)+1;
416   updateRect.height = (y2-y1+1)*(POINTSIZE+1)+1;
417   gtk_widget_draw(drawingArea,&updateRect); 
418 }
419
420 void UpdatePoints(GtkWidget *widget) {
421   UpdatePointsRectangle(widget,0,0,bitmap.width-1,bitmap.height-1);
422 }
423
424 /* this redraw all logo points in previewArea, NO DRAWING AREA */
425 void UpdatePreviewPoints (void) {
426   GdkRectangle updateRect;
427   int x, y, dx = 0, dy = 0;
428
429   if (!previewPixmap || !previewAvailable) return;  
430   
431   if (bitmap.type != GSM_StartupLogo) {
432     dx = PREVIEWJUMPX;
433     dy = PREVIEWJUMPY;
434   }
435
436   for (y = 0;y < bitmap.height;y++)
437     for (x = 0;x < bitmap.width;x++) {
438       if (IsPoint(x,y)) {
439         gdk_draw_point(previewPixmap,previewArea->style->black_gc,
440                        x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy);
441       } else {
442         gdk_draw_pixmap(previewPixmap,
443                         previewArea->style->fg_gc[GTK_WIDGET_STATE(previewArea)],
444                         greenPixelPixmap,0,0,
445                         x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy,1,1);
446       }
447     }
448               
449   updateRect.x = dx; 
450   updateRect.y = dy;
451   updateRect.width = bitmap.width;
452   updateRect.height = bitmap.height;
453   gtk_widget_draw(previewArea,&updateRect);
454 }
455
456 /* ******************************************************
457  * **** DRAWING TOOLS ***********************************
458  * ******************************************************
459  */
460
461 /* TOOL - BRUSH */
462 void ToolBrush(GtkWidget *widget, int column, int row, int button) {
463   /* only this tool directly update bitmap & screen */
464   if (button > 1) 
465     ClearPoint(widget,column,row,1);
466   else
467     SetPoint(widget,column,row,1);
468 }
469
470 /* TOOL - LINE */
471
472 /* this function clear or draw a line on the screen  USED BY TOOLLINEUPDATE */
473 void ToolLine(GtkWidget *widget, int x1, int y1, int x2, int y2, int draw) {
474         int udx, udy, dx, dy, error, loop, xadd, yadd;
475
476         dx = x2 - x1;  /* x delta */
477         dy = y2 - y1;  /* y delta */
478
479         udx = abs(dx); /* unsigned x delta */
480         udy = abs(dy); /* unsigned y delta */
481
482         if (dx < 0) { xadd = -1; } else { xadd = 1; } /* set directions */
483         if (dy < 0) { yadd = -1; } else { yadd = 1; }
484
485         error = 0;
486         loop = 0;
487         if (udx > udy) { /* delta X > delta Y */
488                 do {
489                         error += udy;
490
491                         if (error >= udx) {  /* is time to move up or down? */
492                                 error -= udx;
493                                 y1 += yadd;
494                         }
495                         loop++;
496                         if (draw == 1) {
497                                 SetPoint(widget,x1,y1,0);
498                         } else {
499                                 /* now clearing line before drawing new one, we must check */
500                                 /* if there is a point in oldBitmap which saves bitmap before */
501                                 /* we starting drawing new line */
502                                 if (!GSM_IsPointBitmap(&oldBitmap,x1,y1)) {
503                                         ClearPoint(widget,x1,y1,0);
504                                 }
505                         }
506                         x1 += xadd;         /* move horizontally */
507                 } while (loop < udx); /* repeat for x length */
508         } else {
509                 do {
510                         error += udx;
511                         if (error >= udy) {  /* is time to move left or right? */
512                                 error -= udy;
513                                 x1 += xadd;
514                         }
515                         loop++;
516                         if (draw == 1) {
517                                 SetPoint(widget,x1,y1,0);
518                         } else {
519                                 /* check comment in delta X > delta Y */
520                                 if (!GSM_IsPointBitmap(&oldBitmap,x1,y1)) {
521                                         ClearPoint(widget,x1,y1,0);
522                                 }
523                         }
524                         y1 += yadd;         /* move vertically */
525                 } while (loop < udy); /* repeat for y length */
526         }
527 }
528
529 /* going to rewrite to Bresenham algorithm */ 
530 void ToolLineUpdate(GtkWidget *widget, int column, int row) {
531         /* clear old line */
532         ToolLine(widget,toolStartX,toolStartY,toolLastX,toolLastY,0);
533         /* draw new one */
534         ToolLine(widget,toolStartX,toolStartY,column,row,1);
535 }
536
537 /* TOOL - FILLED RECT */
538
539 /* FIXME - going to rewrite for optimalized version, clearing and */
540 /*         drawing new parts only before clearing and drawing whole */
541 /*         filled rectangle - it's too slow on diskless terminal ;(( */
542 void ToolFilledRectangleUpdate(GtkWidget *widget, int column, int row) {
543   int i, j, x1, y1, x2, y2;
544
545         /* swap Xs to x1 < x2 */
546   if (toolStartX > toolLastX) {
547     x1 = toolLastX;
548     x2 = toolStartX;
549   } else {
550     x1 = toolStartX;
551     x2 = toolLastX;
552   }
553
554         /* swap Ys to y1 < y2 */
555   if (toolStartY > toolLastY) {
556     y1 = toolLastY;
557     y2 = toolStartY;
558   } else {
559     y1 = toolStartY;
560     y2 = toolLastY;
561   }
562
563         /* clear one now */
564   for (j = y1;j <= y2;j++)
565     for (i = x1;i <= x2;i++)
566       if (!GSM_IsPointBitmap(&oldBitmap,i,j)) ClearPoint(widget,i,j,0);
567
568         /* swap Xs to x1 < x2 */
569   if (toolStartX > column) {
570     x1 = column;
571     x2 = toolStartX;
572   } else {
573     x1 = toolStartX;
574     x2 = column;
575   }
576
577         /* swap Ys to y1 < y2 */
578   if (toolStartY > row) {
579     y1 = row;
580     y2 = toolStartY;
581   } else {
582     y1 = toolStartY;
583     y2 = row;
584   }
585
586         /* draw new one */
587   for (j = y1;j <= y2;j++)
588     for (i = x1;i <= x2;i++)
589       SetPoint(widget,i,j,0);
590 }
591
592 /* TOOL - RECTANGLE */
593 void ToolRectangleUpdate(GtkWidget *widget, int column, int row) {
594   int i, j, x1, y1, x2, y2;
595
596   /* clear old rectangle */
597         /* swap Xs to x1 < x2 */
598   if (toolStartX > toolLastX) {
599     x1 = toolLastX;
600     x2 = toolStartX;
601   } else {
602     x1 = toolStartX;
603     x2 = toolLastX;
604   }
605
606         /* swap Ys to y1 < y2 */
607   if (toolStartY > toolLastY) {
608     y1 = toolLastY;
609     y2 = toolStartY;
610   } else {
611     y1 = toolStartY;
612     y2 = toolLastY;
613   }
614
615         /* clear old one */
616   for (i = x1;i <= x2;i++) {
617     if (!GSM_IsPointBitmap(&oldBitmap,i,y1)) ClearPoint(widget,i,y1,0);
618     if (!GSM_IsPointBitmap(&oldBitmap,i,y2)) ClearPoint(widget,i,y2,0);                
619   }
620
621   for (j = y1;j <= y2;j++) {
622     if (!GSM_IsPointBitmap(&oldBitmap,x1,j)) ClearPoint(widget,x1,j,0);
623     if (!GSM_IsPointBitmap(&oldBitmap,x2,j)) ClearPoint(widget,x2,j,0);
624   }
625
626   /* draw new rectangle */
627         /* swap Xs to x1 < x2 */
628   if (toolStartX > column) {
629     x1 = column;
630     x2 = toolStartX;
631   } else {
632     x1 = toolStartX;
633     x2 = column;
634   }
635
636         /* swap Ys to y1 < y2 */
637   if (toolStartY > row) {
638     y1 = row;
639     y2 = toolStartY;
640   } else {
641     y1 = toolStartY;
642     y2 = row;
643   }
644
645         /* draw new one */
646   for (i = x1;i <= x2;i++) {
647     if (!IsPoint(i,y1)) SetPoint(widget,i,y1,0);
648     if (!IsPoint(i,y2)) SetPoint(widget,i,y2,0);
649   }
650
651   for (j = y1;j <= y2;j++) {
652     if (!IsPoint(x1,j)) SetPoint(widget,x1,j,0);
653     if (!IsPoint(x2,j)) SetPoint(widget,x2,j,0);
654   }
655 }
656
657 /* this update tools actions on the screen - this is for optimalization */
658 /* eg. for faster redrawing tools actions - we do not need redraw pixel */
659 /* by pixel. Faster is redraw whole rectangle which contains all changes */
660 void UpdateToolScreen(GtkWidget *widget, int x1, int y1, int x2, int y2) {
661   GdkRectangle updateRect;
662
663   /* update preview area */
664         if (previewAvailable) {
665           updateRect.x = PREVIEWSTARTX+x1;
666         updateRect.y = PREVIEWSTARTY+y1;
667           if (bitmap.type != GSM_StartupLogo) {
668           updateRect.x += PREVIEWJUMPX;
669             updateRect.y += PREVIEWJUMPY;
670         }
671           updateRect.width = x2-x1+1;
672         updateRect.height = y2-y1+1;
673         gtk_widget_draw(previewArea,&updateRect);
674         }
675
676   /* update drawing area */
677   updateRect.x = x1 * (POINTSIZE+1);
678   updateRect.y = y1 * (POINTSIZE+1);
679   updateRect.width = (x2-x1+1)*(POINTSIZE+2);
680   updateRect.height = (y2-y1+1)*(POINTSIZE+2);
681   gtk_widget_draw(drawingArea,&updateRect);
682 }
683
684 /* *************************************
685  * ** PREVIEW AREA EVENTS **************
686  * *************************************
687  */
688
689 gint PreviewAreaButtonPressEvent(GtkWidget *widget, GdkEventButton *event) {
690   previewPixmapNumber = (previewPixmapNumber % 8) + 1;
691
692   gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
693                         previewPixmapWidth,previewPixmapHeight);
694
695   return TRUE;
696 }
697
698 gint PreviewAreaConfigureEvent(GtkWidget *widget, GdkEventConfigure *event) {
699   if (previewPixmap) gdk_pixmap_unref(previewPixmap);
700   previewPixmap = GetPreviewPixmap(widget);
701
702   UpdatePreviewPoints();
703         
704   return TRUE;
705 }
706
707 gint PreviewAreaExposeEvent(GtkWidget *widget, GdkEventExpose *event) {
708   /* got previewPixmap? */
709   if (previewPixmap)
710     /* yes - simply redraw some rectangle */      
711     gdk_draw_pixmap(widget->window,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
712                     previewPixmap,event->area.x,event->area.y,event->area.x,
713                     event->area.y,event->area.width,event->area.height);
714
715   return FALSE;
716 }
717
718 /* ********************************
719  * ** DRAWING AREA EVENTS *********
720  * ********************************
721  */
722
723 gint DrawingAreaButtonPressEvent(GtkWidget *widget, GdkEventButton *event) {
724   /* got drawingPixmap? */
725   if (drawingPixmap == NULL) return TRUE;
726
727   if (!mouseButtonPushed) {
728     if ((event->button == 1 && activeTool != TOOL_BRUSH) || 
729         (activeTool == TOOL_BRUSH)) {
730       /* position from we starting drawing */
731       toolStartX = event->x / (POINTSIZE+1);
732       if (toolStartX < 0) toolStartX = 0;
733       if (toolStartX > bitmap.width-1) toolStartX = bitmap.width-1;
734     
735       toolStartY = event->y / (POINTSIZE+1);
736       if (toolStartY < 0) toolStartY = 0;
737       if (toolStartY > bitmap.height-1) toolStartY = bitmap.height-1;
738
739       toolLastX = toolStartX;
740       toolLastY = toolStartY;
741
742       /* store old bitmap for drawing, resp. for moving, resizing primitive */
743       memcpy(&oldBitmap,&bitmap,sizeof(oldBitmap));
744     }
745
746     if (event->button == 1) mouseButtonPushed = 1;
747   
748     switch (activeTool) { 
749       case TOOL_BRUSH:
750         ToolBrush(widget,toolStartX,toolStartY,event->button);
751         break;
752       case TOOL_LINE:
753       case TOOL_RECTANGLE:
754         if (event->button == 1) ToolBrush(widget,toolStartX,toolStartY,event->button);
755         break;
756     }
757   }
758
759   /* user is drawing some tool other than TOOL_BRUSH and pushed mouse button
760    * another than first => cancel tool and redraw to oldBitmap (bitmap when
761    * user start drawing)
762    */
763   if (mouseButtonPushed && activeTool != TOOL_BRUSH && event->button != 1) {
764     int lowestX, lowestY, highestX, highestY;
765     int i, j;
766
767     lowestX  = GetMinFrom3(toolStartX,toolLastX,toolLastX);
768     lowestY  = GetMinFrom3(toolStartY,toolLastY,toolLastY);
769     highestX = GetMaxFrom3(toolStartX,toolLastX,toolLastX);
770     highestY = GetMaxFrom3(toolStartY,toolLastY,toolLastY);
771
772     for (j = lowestY;j <= highestY;j++)
773       for (i = lowestX;i <= highestX;i++)
774         if (GSM_IsPointBitmap(&oldBitmap,i,j))
775           SetPoint(widget,i,j,0);
776         else
777           ClearPoint(widget,i,j,0);
778     UpdateToolScreen(widget,lowestX,lowestY,highestX,highestY);
779
780     mouseButtonPushed = 0;
781   }
782
783   return TRUE;
784 }
785
786 gint DrawingAreaButtonReleaseEvent(GtkWidget *widget, GdkEventButton *event) {
787   if (event->button == 1)
788     mouseButtonPushed = 0;
789
790   return TRUE;
791 }
792
793 gint DrawingAreaMotionNotifyEvent(GtkWidget *widget, GdkEventMotion *event) {
794   int x,y;
795   GdkModifierType state;
796   
797   if (!mouseButtonPushed && activeTool != TOOL_BRUSH) return TRUE;
798   
799   if (event->is_hint)
800     gdk_window_get_pointer(event->window,&x,&y,&state);
801   else {
802     x = event->x;
803     y = event->y;
804     state = event->state;
805   }
806
807   x = x / (POINTSIZE+1);
808   y = y / (POINTSIZE+1);
809   if (x < 0) x = 0;
810   if (y < 0) y = 0;
811   if (x > bitmap.width-1) x = bitmap.width-1;
812   if (y > bitmap.height-1) y = bitmap.height-1;
813
814   if (y == toolLastY && x == toolLastX) return TRUE;
815   
816   switch (activeTool) {
817     case TOOL_BRUSH:
818       if (state & GDK_BUTTON1_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,1);
819       if (state & GDK_BUTTON2_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,2);
820       if (state & GDK_BUTTON3_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,3);
821       break;
822     case TOOL_RECTANGLE:
823       if (drawingPixmap != NULL) ToolRectangleUpdate(widget,x,y);
824       break;
825     case TOOL_FILLED_RECTANGLE:
826       if (drawingPixmap != NULL) ToolFilledRectangleUpdate(widget,x,y); 
827       break; 
828     case TOOL_LINE:
829       if (drawingPixmap != NULL) ToolLineUpdate(widget,x,y); 
830       break; 
831   }   
832
833   /* what is this?
834    * it's simple, above tools updates only bitmap in memory and this
835    * function update from bitmap to screen, it's made as non-blinking
836    * drawing functions with this, simply draw everything we need and
837    * after that, redraw to screen rectangle in which we made changes 
838    * it's not redrawing pixel by pixel (blinking)
839    */
840   if (activeTool != TOOL_BRUSH) {
841     int lowestX, lowestY, highestX, highestY;
842
843     lowestX  = GetMinFrom3(toolStartX,toolLastX,x);
844     lowestY  = GetMinFrom3(toolStartY,toolLastY,y);
845     highestX = GetMaxFrom3(toolStartX,toolLastX,x);
846     highestY = GetMaxFrom3(toolStartY,toolLastY,y);
847   
848     UpdateToolScreen(widget,lowestX,lowestY,highestX,highestY);  
849   }
850
851   toolLastX = x;
852   toolLastY = y; 
853   return TRUE;  
854 }
855
856 /* configureEvent? -> event when someone resize windows, ... */
857 gint DrawingAreaConfigureEvent(GtkWidget *widget, GdkEventConfigure *event) {
858   int x, y;
859   /* got drawingPixmap? */
860   if (drawingPixmap) gdk_pixmap_unref(drawingPixmap); /* got, erase it */
861
862   /* make a new pixmap */
863   drawingPixmap = gdk_pixmap_new(widget->window,drawingAreaWidth,
864                   drawingAreaHeight,-1);
865
866   /* draw grid into pixmap */
867   for (y = 0;y < bitmap.height;y++)
868     for (x = 0;x < bitmap.width;x++)
869       if (IsPoint(x,y))
870         gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
871                         blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
872       else
873         gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
874                         greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
875   
876   return TRUE;
877 }
878
879 gint DrawingAreaExposeEvent(GtkWidget *widget, GdkEventExpose *event) {
880   /* got drawingPixmap? */
881   if (drawingPixmap)
882     /* got - draw it */
883     gdk_draw_pixmap(widget->window,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
884                     drawingPixmap,
885                     event->area.x,event->area.y,event->area.x,event->area.y,
886                     event->area.width,event->area.height);
887   return FALSE; 
888 }
889
890 /* *****************************************
891  * ** TOOLBAR & MENU EVENTS ****************
892  * *****************************************
893  */
894
895 void GetNetworkInfoEvent(GtkWidget *widget) {
896   GSM_Error error;
897   PhoneEvent *e = (PhoneEvent *)g_malloc(sizeof(PhoneEvent));
898   D_NetworkInfo *data = (D_NetworkInfo *)g_malloc(sizeof(D_NetworkInfo));
899
900   /* prepare data for event */
901   data->info = &networkInfo;
902   e->event = Event_GetNetworkInfo;
903   e->data = data;
904
905   /* launch event and wait for result */
906   GUI_InsertEvent(e);
907   pthread_mutex_lock(&getNetworkInfoMutex);
908   pthread_cond_wait(&getNetworkInfoCond,&getNetworkInfoMutex);
909   pthread_mutex_unlock(&getNetworkInfoMutex);
910   error = data->status;
911   g_free(data);
912
913   /* watch for errors */
914   if (error != GE_NONE) {
915     gchar *buf = g_strdup_printf(_("Error getting network info\n(error=%d)"),error);
916     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
917     gtk_widget_show(errorDialog.dialog);
918     g_free(buf);
919   }
920
921   /* set new operator name to combo */
922   gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry),
923                GSM_GetNetworkName(networkInfo.NetworkCode));
924 }
925
926 void GetLogoEvent(GtkWidget *widget) {
927   GSM_Error error;
928   int i;
929   PhoneEvent *e = (PhoneEvent *) g_malloc(sizeof(PhoneEvent));
930   D_Bitmap *data = (D_Bitmap *)g_malloc(sizeof(D_Bitmap));
931   char *operator = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry));
932
933   /* prepare data for event */
934   strncpy(bitmap.netcode,GSM_GetNetworkCode(operator),7);
935   data->bitmap = &bitmap;
936   e->event = Event_GetBitmap;
937   e->data = data;
938   if (phoneMonitor.supported & PM_CALLERGROUP) {
939     for (i = 0;i < 6;i++) 
940       if (strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(callerCombo)->entry)),
941                  xgnokiiConfig.callerGroups[i]) == 0) bitmap.number = i; 
942   }
943
944   /* launch event and wait for result */
945   GUI_InsertEvent(e);
946   pthread_mutex_lock(&getBitmapMutex);
947   pthread_cond_wait(&getBitmapCond,&getBitmapMutex);
948   pthread_mutex_unlock(&getBitmapMutex);
949   error = data->status;
950   g_free(data);
951
952   /* watch for errors */
953   if (error != GE_NONE) {
954     gchar *buf = g_strdup_printf(_("Error getting bitmap\n(error=%d)"),error);
955     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
956     gtk_widget_show(errorDialog.dialog);
957     g_free(buf);
958   } else {
959     /* no error, draw logo from phone */
960     UpdatePoints(drawingArea);
961   }
962 }
963
964 void SetLogoEvent(GtkWidget *widget) {
965   GSM_Error error;
966   PhoneEvent *e = (PhoneEvent *)g_malloc(sizeof(PhoneEvent));
967   D_Bitmap *data = (D_Bitmap *)g_malloc(sizeof(D_Bitmap));
968   char *operator = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry));
969   int i;
970
971   /* prepare data */
972   strncpy(bitmap.netcode,GSM_GetNetworkCode(operator),7);
973  
974   if (bitmap.type == GSM_CallerLogo) {
975     /* above condition must be there, because if you launch logos before
976      * callerGroups are available, you will see segfault - callerGroups not initialized 
977      */
978     if (phoneMonitor.supported & PM_CALLERGROUP) {
979       for (i = 0;i < 6;i++) 
980         if (strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(callerCombo)->entry)),
981                    xgnokiiConfig.callerGroups[i]) == 0) bitmap.number = i; 
982     }  
983   }
984   
985   data->bitmap = &bitmap;
986   e->event = Event_SetBitmap;
987   e->data = data;
988
989   /* launch event and wait for result */
990   GUI_InsertEvent(e);
991   pthread_mutex_lock(&setBitmapMutex);
992   pthread_cond_wait(&setBitmapCond,&setBitmapMutex);
993   pthread_mutex_unlock(&setBitmapMutex);
994   error = data->status;
995   g_free(data);
996
997   /* watch for errors */
998   if (error != GE_NONE) {
999     gchar *buf = g_strdup_printf(_("Error setting bitmap\n(error=%d)"),error);
1000     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1001     gtk_widget_show(errorDialog.dialog);
1002     g_free(buf);
1003   }
1004 }
1005
1006 static void ClearLogoEvent(GtkWidget *widget) {
1007   
1008   //  bitmap.size=bitmap.width*bitmap.height/8;
1009   
1010   GSM_ClearBitmap(&bitmap);
1011
1012   UpdatePoints(widget);
1013 }
1014
1015 void InvertLogoEvent(GtkWidget *widget) {
1016   int column, row;
1017
1018   for (column = 0;column < bitmap.width;column++)
1019     for (row = 0;row < bitmap.height;row++)
1020       if (IsPoint(column,row))
1021         GSM_ClearPointBitmap(&bitmap,column,row);
1022       else
1023         GSM_SetPointBitmap(&bitmap,column,row);
1024
1025   UpdatePoints(widget);
1026 }
1027
1028 void UpLogoEvent(GtkWidget *widget) {
1029   int column, row;
1030
1031   GSM_Bitmap tbitmap;
1032   
1033   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1034   
1035   for (row = 0;row < bitmap.height-1;row++)
1036     for (column = 0;column < bitmap.width;column++)
1037       if (IsPoint(column,row+1))
1038         GSM_SetPointBitmap(&bitmap,column,row);
1039       else
1040         GSM_ClearPointBitmap(&bitmap,column,row);
1041
1042   for (column = 0;column < bitmap.width;column++)
1043     if (GSM_IsPointBitmap(&tbitmap,column,0))
1044       GSM_SetPointBitmap(&bitmap,column,bitmap.height-1);
1045     else
1046       GSM_ClearPointBitmap(&bitmap,column,bitmap.height-1);    
1047
1048   UpdatePoints(widget); 
1049 }
1050
1051 void DownLogoEvent(GtkWidget *widget) {
1052   int column, row;
1053
1054   GSM_Bitmap tbitmap;
1055   
1056   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1057
1058   for (row = bitmap.height-1;row > 0;row--)
1059     for (column = 0;column < bitmap.width;column++)
1060       if (IsPoint(column,row-1))
1061         GSM_SetPointBitmap(&bitmap,column,row);
1062       else
1063         GSM_ClearPointBitmap(&bitmap,column,row);
1064
1065   for (column = 0;column < bitmap.width;column++)
1066     if (GSM_IsPointBitmap(&tbitmap,column,bitmap.height-1))
1067       GSM_SetPointBitmap(&bitmap,column,0);
1068     else
1069       GSM_ClearPointBitmap(&bitmap,column,0);
1070
1071   UpdatePoints(widget);
1072 }
1073
1074 void LeftLogoEvent(GtkWidget *widget) {
1075   int column, row;
1076
1077   GSM_Bitmap tbitmap;
1078   
1079   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1080
1081   for (column = 0; column < bitmap.width-1;column++)
1082     for (row = 0;row < bitmap.height;row++)
1083       if (IsPoint(column+1,row))
1084         GSM_SetPointBitmap(&bitmap,column,row);
1085       else
1086         GSM_ClearPointBitmap(&bitmap,column,row);
1087
1088   for (row = 0;row < bitmap.height;row++)
1089     if (GSM_IsPointBitmap(&tbitmap,0,row))
1090       GSM_SetPointBitmap(&bitmap,bitmap.width-1,row);
1091     else
1092       GSM_ClearPointBitmap(&bitmap,bitmap.width-1,row);
1093
1094   UpdatePoints(widget);
1095 }
1096
1097 void RightLogoEvent(GtkWidget *widget) {
1098   int column, row;
1099
1100   GSM_Bitmap tbitmap;
1101   
1102   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1103
1104   for (column = bitmap.width-1;column > 0;column--)
1105     for (row = 0;row < bitmap.height;row++)
1106       if (IsPoint(column-1,row))
1107         GSM_SetPointBitmap(&bitmap,column,row);
1108       else
1109         GSM_ClearPointBitmap(&bitmap,column,row);
1110
1111   for (row = 0;row < bitmap.height;row++)
1112     if (GSM_IsPointBitmap(&tbitmap,bitmap.width-1,row))
1113       GSM_SetPointBitmap(&bitmap,0,row);
1114     else
1115       GSM_ClearPointBitmap(&bitmap,0,row);
1116
1117   UpdatePoints(widget);
1118 }
1119
1120 void FlipVerticalLogoEvent(GtkWidget *widget) {
1121   int row, column, temp;
1122
1123   for (row = 0;row < (bitmap.height/2);row++)
1124     for (column = 0;column < bitmap.width;column++) {
1125       temp = IsPoint(column,row);
1126       if (IsPoint(column,bitmap.height-1-row))
1127         GSM_SetPointBitmap(&bitmap,column,row);
1128       else
1129         GSM_ClearPointBitmap(&bitmap,column,row);
1130
1131       if (temp)
1132         GSM_SetPointBitmap(&bitmap,column,bitmap.height-1-row);
1133       else
1134         GSM_ClearPointBitmap(&bitmap,column,bitmap.height-1-row);
1135     }
1136
1137   UpdatePoints(widget);
1138 }
1139
1140 void FlipHorizontalLogoEvent(GtkWidget *widget) {
1141   int row, column, temp;
1142
1143   for (row = 0;row < bitmap.height;row++)
1144     for (column = 0;column < (bitmap.width/2);column++) {
1145       temp = IsPoint(column,row);
1146
1147       if (IsPoint(bitmap.width-1-column,row))
1148         GSM_SetPointBitmap(&bitmap,column,row);
1149       else
1150         GSM_ClearPointBitmap(&bitmap,column,row);
1151
1152       if (temp)
1153         GSM_SetPointBitmap(&bitmap,bitmap.width-1-column,row);
1154       else
1155         GSM_ClearPointBitmap(&bitmap,bitmap.width-1-column,row);
1156     }
1157
1158   UpdatePoints(widget);
1159
1160
1161 /* this is launched when tool was changed */
1162 gint ToolTypeEvent(GtkWidget *widget) {
1163   if (GTK_TOGGLE_BUTTON(buttonBrush)->active) activeTool = TOOL_BRUSH; else
1164   if (GTK_TOGGLE_BUTTON(buttonLine)->active) activeTool = TOOL_LINE; else
1165   if (GTK_TOGGLE_BUTTON(buttonRectangle)->active) activeTool = TOOL_RECTANGLE; else
1166   if (GTK_TOGGLE_BUTTON(buttonFilledRectangle)->active)
1167     activeTool = TOOL_FILLED_RECTANGLE;
1168
1169   return 0;
1170 }
1171
1172 /* this is launched when logo type was change by buttons on toolbar */
1173 gint LogoTypeEvent(GtkWidget *widget) {
1174   int clear = 0;
1175
1176   /* is startupLogo? */
1177   /* Resize and clear anyway - CK */
1178   if (GTK_TOGGLE_BUTTON(buttonStartup)->active) {
1179     /* look for old bitmap type, clean if another */
1180     clear = 1;
1181     GSM_ResizeBitmap(&bitmap,GSM_StartupLogo, &statemachine.Phone.Info);
1182   }
1183
1184   /* has phone support for callerGroups? */
1185   if (phoneMonitor.supported & PM_CALLERGROUP) {
1186     if (GTK_TOGGLE_BUTTON(buttonCaller)->active && bitmap.type != GSM_CallerLogo) {
1187       /* previous was startup? clear and draw batteries, signal, ... */      
1188             /* Clear anyway for 7110...CK */
1189       clear = 1;
1190       GSM_ResizeBitmap(&bitmap,GSM_CallerLogo, &statemachine.Phone.Info);
1191     }
1192   }
1193
1194   /* is new type operatorLogo? */
1195   if (GTK_TOGGLE_BUTTON(buttonOperator)->active && bitmap.type != GSM_OperatorLogo) {
1196     /* previous startup? clear and draw batteries, signal, ... */      
1197           /* Clear anyway for 7110..CK */
1198     clear = 1;
1199     GSM_ResizeBitmap(&bitmap,GSM_OperatorLogo, &statemachine.Phone.Info);
1200   }
1201
1202   /* must clear? */
1203   if (clear) {
1204     if (previewAvailable) {
1205       /* configure event reload pixmap from disk and redraws */
1206       gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
1207                             previewPixmapWidth,previewPixmapHeight);
1208     }   
1209
1210     /* change new drawingArea size */
1211     drawingAreaWidth = bitmap.width * (POINTSIZE+1)+1;
1212     drawingAreaHeight = bitmap.height * (POINTSIZE+1)+1;
1213
1214     gtk_drawing_area_size(GTK_DRAWING_AREA(drawingArea),
1215                           drawingAreaWidth,drawingAreaHeight);
1216   }
1217
1218   return 0;
1219 }
1220
1221 inline void CloseLogosWindow (void) {
1222   gtk_widget_hide(GUI_LogosWindow);
1223 }
1224
1225 void ExportLogoFileMain(gchar *name)
1226 {
1227   GSM_Bitmap tbitmap;
1228   GSM_Error error;
1229   
1230   tbitmap=bitmap;
1231
1232   strncpy(tbitmap.netcode,GSM_GetNetworkCode(networkInfo.NetworkCode),7);
1233
1234   error=GSM_SaveBitmapFile(name,&tbitmap);
1235   if (error!=GE_NONE) {
1236     gchar *buf = g_strdup_printf(_("Error saving file\n(error=%d)"),error);
1237     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1238     gtk_widget_show(errorDialog.dialog);
1239     g_free(buf);
1240   }
1241 }
1242
1243 static void YesLogoFileExportDialog (GtkWidget *w, gpointer data)
1244 {
1245   gtk_widget_hide (GTK_WIDGET (data));
1246   ExportLogoFileMain(exportDialogData.fileName);
1247 }
1248
1249 static void ExportFileSelected (GtkWidget *w, GtkFileSelection *fs)
1250 {
1251   static YesNoDialog dialog = { NULL, NULL};
1252   FILE *f;
1253   gchar err[80];
1254
1255   exportDialogData.fileName = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
1256   gtk_widget_hide (GTK_WIDGET (fs));
1257
1258   if ((f = fopen (exportDialogData.fileName, "r")) != NULL)
1259   {
1260     fclose (f);
1261     if (dialog.dialog == NULL)
1262     {
1263       CreateYesNoDialog (&dialog, YesLogoFileExportDialog, CancelDialog, GUI_LogosWindow);
1264       gtk_window_set_title (GTK_WINDOW (dialog.dialog), _("Overwrite file?"));
1265       g_snprintf ( err, 80, _("File %s already exist.\nOverwrite?"), exportDialogData.fileName); 
1266       gtk_label_set_text (GTK_LABEL(dialog.text), err);
1267     }
1268     gtk_widget_show (dialog.dialog);
1269   }
1270   else
1271     ExportLogoFileMain(exportDialogData.fileName);
1272 }
1273
1274 void ImportFileSelected(GtkWidget *w, GtkFileSelection *fs)
1275 {
1276   GSM_Bitmap tbitmap;
1277   GSM_Error error=0;
1278   
1279   gchar *fileName;
1280   FILE *f;
1281
1282   fileName = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
1283   gtk_widget_hide (GTK_WIDGET (fs));
1284
1285   if ((f = fopen (fileName, "r")) == NULL) {
1286     gchar *buf = g_strdup_printf(_("Can't open file %s for reading !"),fileName);
1287     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1288     gtk_widget_show(errorDialog.dialog);
1289     g_free(buf);
1290     return;
1291   } else fclose(f);
1292
1293   error=GSM_ReadBitmapFile(fileName,&tbitmap);
1294   if (error!=GE_NONE) {
1295     gchar *buf = g_strdup_printf(_("Error reading file\n(error=%d)"),error);
1296     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1297     gtk_widget_show(errorDialog.dialog);
1298     g_free(buf);
1299     return;
1300   }
1301
1302   exportDialogData.fileName=fileName;
1303   
1304   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonStartup),false);
1305   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonOperator),false);
1306   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonCaller),false);
1307   
1308   if (tbitmap.type==GSM_OperatorLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonOperator),true);
1309   if (tbitmap.type==GSM_StartupLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonStartup),true);
1310   if (tbitmap.type==GSM_CallerLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonCaller),true);
1311   
1312   memcpy(&bitmap,&tbitmap,sizeof(GSM_Bitmap));
1313   
1314   UpdatePoints(drawingArea);
1315 }
1316
1317 void SaveLogoAs(GtkWidget *widget)
1318 {
1319   FileSelection=gtk_file_selection_new (_("Save logo as ..."));
1320
1321   gtk_signal_connect (
1322         GTK_OBJECT (GTK_FILE_SELECTION (FileSelection)->ok_button),
1323         "clicked", (GtkSignalFunc) ExportFileSelected, FileSelection);
1324     
1325   gtk_signal_connect_object (
1326         GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->cancel_button),
1327         "clicked", (GtkSignalFunc) gtk_widget_destroy,
1328         GTK_OBJECT (FileSelection));
1329     
1330   gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(FileSelection));
1331
1332   gtk_widget_show(FileSelection);
1333 }
1334
1335 void SaveLogo(GtkWidget *widget)
1336 {
1337   if (exportDialogData.fileName==NULL) {
1338     SaveLogoAs(widget);
1339   } else {
1340     ExportLogoFileMain(exportDialogData.fileName);
1341   }
1342 }
1343
1344 void OpenLogo(GtkWidget *widget)
1345 {
1346   FileSelection=gtk_file_selection_new (_("Open logo..."));
1347
1348   gtk_signal_connect (
1349         GTK_OBJECT (GTK_FILE_SELECTION (FileSelection)->ok_button),
1350         "clicked", (GtkSignalFunc) ImportFileSelected, FileSelection);
1351     
1352   gtk_signal_connect_object (
1353         GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->cancel_button),
1354         "clicked", (GtkSignalFunc) gtk_widget_destroy,
1355         GTK_OBJECT (FileSelection));
1356     
1357   gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(FileSelection));
1358
1359   gtk_widget_show(FileSelection);
1360 }
1361
1362 static GtkItemFactoryEntry logosMenuItems[] = {
1363   { NULL,       NULL,           NULL,                    0, "<Branch>"},
1364   { NULL,       "<control>O",   OpenLogo,                0, NULL},
1365   { NULL,       "<control>S",   SaveLogo,                0, NULL},
1366   { NULL,       NULL,           SaveLogoAs,              0, NULL},
1367   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1368   { NULL,       "<control>G",   GetNetworkInfoEvent,     0, NULL},
1369   { NULL,       NULL,           GetLogoEvent,            0, NULL},
1370   { NULL,       "<control>T",   SetLogoEvent,            0, NULL},
1371   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1372   { NULL,       "<control>W",   CloseLogosWindow,        0, NULL},
1373   { NULL,       NULL,           NULL,                    0, "<Branch>"},
1374   { NULL,       "<control>C",   ClearLogoEvent,          0, NULL},
1375   { NULL,       "<control>I",   InvertLogoEvent,         0, NULL},
1376   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1377   { NULL,       "<control>U",   UpLogoEvent,             0, NULL},
1378   { NULL,       "<control>D",   DownLogoEvent,           0, NULL},
1379   { NULL,       "<control>L",   LeftLogoEvent,           0, NULL},
1380   { NULL,       "<control>R",   RightLogoEvent,          0, NULL},
1381   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1382   { NULL,       "<control>H",   FlipHorizontalLogoEvent, 0, NULL},
1383   { NULL,       "<control>V",   FlipVerticalLogoEvent,   0, NULL},
1384 };
1385
1386 void InitLogosMenu (void) {
1387  logosMenuItems[0].path = g_strdup(_("/_File"));
1388  logosMenuItems[1].path = g_strdup(_("/File/_Open"));
1389  logosMenuItems[2].path = g_strdup(_("/File/_Save"));
1390  logosMenuItems[3].path = g_strdup(_("/File/Save _as ..."));
1391  logosMenuItems[4].path = g_strdup(_("/File/Sep1"));
1392  logosMenuItems[5].path = g_strdup(_("/File/_Get operator"));
1393  logosMenuItems[6].path = g_strdup(_("/File/Get _logo"));
1394  logosMenuItems[7].path = g_strdup(_("/File/Se_t logo"));
1395  logosMenuItems[8].path = g_strdup(_("/File/Sep2"));
1396  logosMenuItems[9].path = g_strdup(_("/File/_Close"));
1397  logosMenuItems[10].path = g_strdup(_("/_Edit"));
1398  logosMenuItems[11].path = g_strdup(_("/Edit/_Clear"));
1399  logosMenuItems[12].path = g_strdup(_("/Edit/_Invert"));
1400  logosMenuItems[13].path = g_strdup(_("/Edit/Sep3"));
1401  logosMenuItems[14].path = g_strdup(_("/Edit/_Up logo"));
1402  logosMenuItems[15].path = g_strdup(_("/Edit/_Down logo"));
1403  logosMenuItems[16].path = g_strdup(_("/Edit/_Left logo"));
1404  logosMenuItems[17].path = g_strdup(_("/Edit/_Right logo"));
1405  logosMenuItems[18].path = g_strdup(_("/Edit/Sep4"));
1406  logosMenuItems[19].path = g_strdup(_("/Edit/Flip _horizontal"));
1407  logosMenuItems[20].path = g_strdup(_("/Edit/Flip _vertical"));
1408 }
1409
1410 void GUI_CreateLogosWindow (void) {
1411   int nMenuItems = sizeof (logosMenuItems) / sizeof (logosMenuItems[0]);
1412   GtkAccelGroup *accelGroup;
1413   GtkItemFactory *itemFactory;
1414   GtkWidget *menuBar;
1415   GtkWidget *toolBar, *vertToolBar;
1416   GtkWidget *vbox;
1417   GtkWidget *hbox;
1418   GtkWidget *drawingBox;
1419   GtkWidget *separator;
1420   GdkBitmap *mask;
1421
1422   GList *glistNetwork = NULL;
1423
1424   int i = 0;
1425  
1426   previewPixmapWidth = PREVIEWWIDTH;
1427   previewPixmapHeight = PREVIEWHEIGHT;
1428   
1429   InitLogosMenu();
1430
1431   /* realize top level window for logos */
1432   GUI_LogosWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1433   gtk_window_set_wmclass(GTK_WINDOW(GUI_LogosWindow), "LogosWindow", "Xgnokii");
1434   gtk_window_set_policy(GTK_WINDOW(GUI_LogosWindow), 1, 1, 1);
1435   gtk_window_set_title(GTK_WINDOW(GUI_LogosWindow), _("Logos"));
1436   gtk_signal_connect(GTK_OBJECT(GUI_LogosWindow), "delete_event",
1437                      GTK_SIGNAL_FUNC(DeleteEvent), NULL);
1438   gtk_widget_realize(GUI_LogosWindow);
1439
1440   CreateErrorDialog(&errorDialog, GUI_LogosWindow);
1441   CreateInfoDialog(&infoDialog, GUI_LogosWindow);
1442
1443   accelGroup = gtk_accel_group_new();
1444   gtk_accel_group_attach(accelGroup, GTK_OBJECT(GUI_LogosWindow));
1445   
1446   /* create main vbox */
1447   vbox = gtk_vbox_new(FALSE, 1);
1448   gtk_container_add(GTK_CONTAINER(GUI_LogosWindow), vbox);
1449   gtk_widget_show(vbox);
1450  
1451   itemFactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accelGroup);
1452   gtk_item_factory_create_items(itemFactory, nMenuItems, logosMenuItems, NULL);
1453   menuBar = gtk_item_factory_get_widget(itemFactory, "<main>");
1454
1455   gtk_box_pack_start(GTK_BOX(vbox), menuBar, FALSE, FALSE, 0);
1456   gtk_widget_show(menuBar);
1457
1458   /* toolbar */
1459   toolBar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
1460   gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolBar), GTK_RELIEF_NORMAL);
1461   gtk_toolbar_set_style(GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS);
1462
1463   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Clear logo"), NULL,
1464                   NewPixmap(New_xpm, GUI_LogosWindow->window,
1465                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1466                   (GtkSignalFunc)ClearLogoEvent, toolBar);
1467
1468   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1469
1470   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Get logo"), NULL,
1471                  NewPixmap(Read_xpm, GUI_LogosWindow->window,
1472                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1473                  (GtkSignalFunc)GetLogoEvent, toolBar);
1474
1475   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Set logo"), NULL,
1476                  NewPixmap(Send_xpm, GUI_LogosWindow->window,
1477                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1478                  (GtkSignalFunc)SetLogoEvent, toolBar);
1479
1480   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1481
1482   gtk_toolbar_append_item (GTK_TOOLBAR (toolBar), NULL, _("Import from file"), NULL,
1483                            NewPixmap(Open_xpm, GUI_LogosWindow->window,
1484                            &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1485                            (GtkSignalFunc) OpenLogo, NULL);
1486   gtk_toolbar_append_item (GTK_TOOLBAR (toolBar), NULL, _("Export to file"), NULL,
1487                            NewPixmap(Save_xpm, GUI_LogosWindow->window,
1488                            &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1489                            (GtkSignalFunc) SaveLogo, NULL);
1490
1491   gtk_toolbar_append_space (GTK_TOOLBAR (toolBar));
1492
1493   buttonStartup = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1494                   GTK_TOOLBAR_CHILD_RADIOBUTTON, NULL, NULL, _("Startup logo"),
1495                   "", NewPixmap(Startup_logo_xpm, GUI_LogosWindow->window,
1496                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1497                   GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1498
1499   buttonOperator = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1500                   GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonStartup, NULL, _("Operator logo"),
1501                   "", NewPixmap(Operator_logo_xpm, GUI_LogosWindow->window,
1502                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1503                   GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1504
1505   buttonCaller = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1506                  GTK_TOOLBAR_CHILD_RADIOBUTTON,
1507                  buttonOperator,
1508                  NULL, _("Caller logo"),
1509                  "", NewPixmap(Caller_logo_xpm, GUI_LogosWindow->window,
1510                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1511                  GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1512
1513   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1514   
1515   networkCombo = gtk_combo_new();
1516   gtk_combo_set_use_arrows_always(GTK_COMBO(networkCombo), 1);
1517   while (strcmp(GSM_Networks[i].Name, "unknown"))
1518     glistNetwork = g_list_insert_sorted(glistNetwork, GSM_Networks[i++].Name,
1519                    (GCompareFunc)strcmp);
1520   gtk_combo_set_popdown_strings(GTK_COMBO(networkCombo), glistNetwork);
1521   gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(networkCombo)->entry), FALSE);
1522   gtk_toolbar_append_widget(GTK_TOOLBAR(toolBar), networkCombo, "", "");
1523   gtk_widget_show(networkCombo);
1524   g_list_free(glistNetwork);
1525
1526   callerCombo = gtk_combo_new();
1527   gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(callerCombo)->entry), FALSE);
1528   gtk_toolbar_append_widget(GTK_TOOLBAR(toolBar), callerCombo, "", "");
1529   gtk_widget_show(callerCombo);
1530   
1531   gtk_box_pack_start(GTK_BOX(vbox), toolBar, FALSE, FALSE, 0);
1532   gtk_widget_show(toolBar); 
1533
1534   /* vertical separator */
1535   separator = gtk_hseparator_new();
1536   gtk_box_pack_start(GTK_BOX(vbox),GTK_WIDGET(separator),FALSE,FALSE,0);
1537   
1538   /* create horizontal box for preview and drawing areas */
1539   hbox = gtk_hbox_new(FALSE,5);
1540   gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
1541   gtk_widget_show(hbox);
1542  
1543   /* set GSM_Bitmap width,height needed for creating drawinArea
1544    * we are starting, default is startupLogo
1545    */
1546   bitmap.type = GSM_StartupLogo;
1547   bitmap.height = 48;
1548   bitmap.width = 84;
1549   bitmap.size = bitmap.height * bitmap.width / 8;
1550   drawingAreaWidth = bitmap.width * (POINTSIZE+1)+1;
1551   drawingAreaHeight = bitmap.height * (POINTSIZE+1)+1;
1552  
1553   /* previewArea */
1554   previewPixmap = GetPreviewPixmap(GUI_LogosWindow);
1555
1556   if (previewPixmap != NULL) {
1557     previewArea = gtk_drawing_area_new();
1558     gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
1559                           previewPixmapWidth,previewPixmapHeight);
1560     
1561     greenPixelPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1562                        &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],
1563                        Green_pixel_xpm);
1564
1565     gtk_signal_connect(GTK_OBJECT(previewArea),"expose_event",
1566                        (GtkSignalFunc)PreviewAreaExposeEvent,NULL);
1567     gtk_signal_connect(GTK_OBJECT(previewArea),"configure_event",
1568                        (GtkSignalFunc)PreviewAreaConfigureEvent,NULL);
1569     gtk_signal_connect(GTK_OBJECT(previewArea),"button_press_event",
1570                        (GtkSignalFunc)PreviewAreaButtonPressEvent,NULL);
1571
1572     gtk_widget_set_events(previewArea,GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK );
1573
1574     gtk_box_pack_start(GTK_BOX(hbox),previewArea,FALSE,FALSE,0);
1575     gtk_widget_show(previewArea);
1576     
1577     /* clear battery, signal, menu & names from preview phone */
1578     UpdatePreviewPoints (); 
1579
1580   } else previewAvailable = 0;
1581
1582   /* drawingArea */
1583   greenPointPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1584                   &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],Green_point_xpm);
1585   blackPointPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1586                   &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],Black_point_xpm);
1587   
1588   drawingBox = gtk_vbox_new(FALSE,3);
1589   gtk_box_pack_start(GTK_BOX(hbox),drawingBox,FALSE,FALSE,0);
1590   gtk_widget_show(drawingBox);
1591
1592   drawingArea = gtk_drawing_area_new();
1593   gtk_drawing_area_size(GTK_DRAWING_AREA(drawingArea),
1594                   drawingAreaWidth,drawingAreaHeight);
1595
1596   gtk_signal_connect(GTK_OBJECT(drawingArea),"configure_event",
1597                   (GtkSignalFunc)DrawingAreaConfigureEvent,NULL);
1598   gtk_signal_connect(GTK_OBJECT(drawingArea),"expose_event",
1599                   (GtkSignalFunc)DrawingAreaExposeEvent,NULL);
1600   gtk_signal_connect(GTK_OBJECT(drawingArea),"button_press_event",
1601                   (GtkSignalFunc)DrawingAreaButtonPressEvent,NULL);
1602   gtk_signal_connect(GTK_OBJECT(drawingArea),"button_release_event",
1603                   (GtkSignalFunc)DrawingAreaButtonReleaseEvent,NULL);
1604   gtk_signal_connect(GTK_OBJECT(drawingArea),"motion_notify_event",
1605                   (GtkSignalFunc)DrawingAreaMotionNotifyEvent,NULL);
1606   
1607   gtk_widget_set_events(drawingArea,GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK |
1608                   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 
1609                   GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
1610
1611   gtk_box_pack_start(GTK_BOX(drawingBox),drawingArea,FALSE,FALSE,0);
1612   gtk_widget_show(drawingArea);
1613
1614   /* vertical tool bar */
1615   vertToolBar = gtk_toolbar_new(GTK_ORIENTATION_VERTICAL,GTK_TOOLBAR_ICONS);
1616   gtk_toolbar_set_button_relief(GTK_TOOLBAR(vertToolBar),GTK_RELIEF_NORMAL);
1617   gtk_toolbar_set_style(GTK_TOOLBAR(vertToolBar),GTK_TOOLBAR_ICONS);
1618
1619   buttonBrush = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1620                 GTK_TOOLBAR_CHILD_RADIOBUTTON, NULL, NULL, _("Brush tool"),
1621                 "", NewPixmap(Tool_brush_xpm, GUI_LogosWindow->window,
1622                 &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1623                 GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1624
1625   buttonLine = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1626                GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonBrush, NULL, _("Line tool"),
1627                "", NewPixmap(Tool_line_xpm, GUI_LogosWindow->window,
1628                &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1629                GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1630
1631   buttonRectangle = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1632                     GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonLine, NULL, _("Rectangle tool"),
1633                     "", NewPixmap(Tool_rectangle_xpm, GUI_LogosWindow->window,
1634                     &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1635                     GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1636
1637   buttonFilledRectangle = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1638                           GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonRectangle, NULL,
1639                           _("Filled rectangle tool"),
1640                           "", NewPixmap(Tool_filled_rectangle_xpm,
1641                           GUI_LogosWindow->window,
1642                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1643                           GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1644
1645   gtk_toolbar_append_space(GTK_TOOLBAR(vertToolBar));
1646  
1647   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Invert logo"), NULL,
1648                           NewPixmap(Edit_invert_xpm, GUI_LogosWindow->window,
1649                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1650                           (GtkSignalFunc)InvertLogoEvent, vertToolBar);
1651
1652   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Horizontal flip"), NULL,
1653                           NewPixmap(Edit_flip_horizontal_xpm, GUI_LogosWindow->window,
1654                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1655                           (GtkSignalFunc)FlipHorizontalLogoEvent, vertToolBar);
1656
1657   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Vertical flip"), NULL,
1658                           NewPixmap(Edit_flip_vertical_xpm, GUI_LogosWindow->window,
1659                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1660                           (GtkSignalFunc)FlipVerticalLogoEvent, vertToolBar);
1661
1662   
1663   gtk_box_pack_start(GTK_BOX(hbox),vertToolBar,FALSE,FALSE,0);
1664   gtk_widget_show(vertToolBar);
1665
1666   GUIEventAdd(GUI_EVENT_CALLERS_GROUPS_CHANGED,&GUI_RefreshLogosGroupsCombo);
1667 }
1668
1669 void GUI_RefreshLogosGroupsCombo (void) {
1670   GList *callerList = NULL;
1671   int i;
1672   
1673   for (i = 0;i < 6;i++)
1674     callerList = g_list_insert(callerList,xgnokiiConfig.callerGroups[i],i);
1675   
1676   gtk_combo_set_popdown_strings(GTK_COMBO(callerCombo),callerList);
1677   g_list_free(callerList);
1678
1679   if (!callersGroupsInitialized) callersGroupsInitialized = 1;
1680 }
1681
1682 void GUI_ShowLogosWindow (void) {
1683   /* Set network name taken from the phone */
1684   GetNetworkInfoEvent(NULL);
1685   /* if phone support caller groups, read callerGroups names */
1686   if (phoneMonitor.supported & PM_CALLERGROUP) {
1687     if (xgnokiiConfig.callerGroups[0] == NULL) {
1688       GUI_Refresh(); 
1689       GUI_InitCallerGroupsInf ();
1690     }
1691     if (!callersGroupsInitialized) GUI_RefreshLogosGroupsCombo (); 
1692     gtk_widget_show(buttonCaller);
1693     gtk_widget_show(callerCombo); 
1694   } else {
1695     /* if not supported, hide widget for handling callerGroups */
1696     gtk_widget_hide(buttonCaller);
1697     gtk_widget_hide(callerCombo); 
1698   }        
1699
1700   /* Call to reset Startup logo size */
1701   LogoTypeEvent(GUI_LogosWindow);
1702
1703   gtk_widget_show(GUI_LogosWindow);
1704
1705   if (!previewAvailable && showPreviewErrorDialog) {
1706     gchar *buf = g_strdup(_("Load preview pixmap error, feature disabled."));
1707     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1708     gtk_widget_show(errorDialog.dialog);
1709     g_free(buf);
1710
1711     showPreviewErrorDialog = 0;
1712   }
1713 }