File: vdkb_about.cc

package info (click to toggle)
vdkbuilder2 2.4.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,680 kB
  • ctags: 4,989
  • sloc: cpp: 40,647; sh: 10,346; ansic: 2,718; makefile: 710; sed: 93
file content (266 lines) | stat: -rw-r--r-- 6,433 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
 * ===========================
 * VDK Builder
 * Version 0.1
 * Revision 0.0
 * November 1998
 * ===========================
 *
 * Copyright (C) 1998,1999 Mario Motta
 * Developed by Mario Motta <mmotta@guest.net>
 *
 * Based on VDK Library 
 * Copyright (C) 1998, Mario Motta <mmotta@guest.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 */ 
#include <vdkb2/vdkb_about.h>
#include <vdkb2/vdkb.h>
#include "pixmaps/stock_button_ok.xpm"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if !HAVE_GNOME
#if ENABLE_NLS
#include <libintl.h>
//#define _(str) gettext(str)
#define _(str) \
    ( g_utf8_validate(gettext(str),-1,NULL) ? \
    gettext(str) : \
    g_locale_to_utf8(gettext(str),-1,NULL,NULL,NULL) )
#define N_(str) str
#else
#define _(str) str
#define N_(str) str 
#endif
#endif


static char buff[512];
static char version[256];
static char* authors = 
"The VDK team:\
 Mario Motta (Italy) \
 Ionutz Borcoman (Romania) \
 Tim Lorenz (Germany) \
 George Boutwell (USA) \
 Pierre-Louis Malatray (France) \
 Mile Lazarovski (Macedonia)";
static int canvasLength = 0;
static int counter = 0;
static VDKFont* canvas0_font = NULL;
static int showed_textW = 0;
static int fontH = 0;
static char* showed_text = authors;
static char* cpuinfo = NULL;
/*
defining signal static table
*/
DEFINE_SIGNAL_MAP(VDKBAboutForm,VDKForm)
  ON_SIGNAL(custombutton0,clicked_signal,Oncustombutton0Click),
  ON_SIGNAL(timer,timer_tick_signal,OnTimer)
END_SIGNAL_MAP

// just an exercise on cpu info
DEFINE_EVENT_LIST(VDKBAboutForm,VDKForm);

bool 
VDKBAboutForm::OnCanvas0ButtonPress(VDKObject*, GdkEvent*)
{
  showed_text = showed_text == cpuinfo ? authors : cpuinfo;
  VDKFont* font = canvas0->Font;
  if(font)
    showed_textW = font->Width(showed_text);
  return true;
}

/*
main form gui setup
*/
void
VDKBAboutForm::GUISetup(void)
{
 struct stat info;
  VDKBuilder* app = dynamic_cast<VDKBuilder*>(Application());
  if(!app)
    return;
  Title = "VDKBuilder";
  Box()->BorderWidth(0);
  VDKFrame* frame = new VDKFrame(this);
  frame->BorderWidth(0);
  frame->Shadow = shadow_out;// shadow_none;// shadow_etched_out;
  vbox = new VDKBox(this,v_box);
  frame->Add(vbox,0,0,0,0);
  Add(frame);
  VDKFrame* frame1 = new VDKFrame(this);
  frame1->BorderWidth(0);
  frame1->Shadow = shadow_in;
  canvas0 = new VDKCanvas(this);
  canvas0->SetSize(294,20);
  //  canvas0->SetTip(_("Click to toggle"));
  frame1->Add(canvas0,0,0,0,0);
  vbox->Add(frame1,0,0,0,0);
  separator1 = new VDKSeparator(this,h_separator);
  vbox->Add(separator1,0,0,0,0);
  //  sprintf(buff,"%s/%s",VDKB_DATADIR,VDKB_LOGO);
  sprintf(buff,"%s/.vdkb2/%s",(char*) app->user_home,VDKB_LOGO);
  if (stat(buff,&info) == -1)
    sprintf(buff,"%s/%s",VDKB_DATADIR,VDKB_LOGO);
  pixmap0 = new VDKImage(this,buff);
  vbox->Add(pixmap0,0,0,0,0);
  separator0 = new VDKSeparator(this,h_separator);
  vbox->Add(separator0,0,0,0,0);
  hbox2 = new VDKBox(this,h_box);
  vbox->Add(hbox2,0,1,1,0);
  hbox2->BorderWidth(0);
  /*
  custombutton0 = new VDKCustomButton(this,
				      (const char**) stock_button_ok_xpm,"Ok",16,(GtkPositionType) 1);
  */
  custombutton0 = new VDKHLButton(this, (const char**) stock_button_ok_xpm);
  custombutton0->SetTip(_("that's all folk !"));
  // custombutton0->SetSize(90,-1);
  hbox2->Add(custombutton0,0,0,0,3);
  label0 = new VDKLabel(this," ");
  // label0->SetSize(150,-1);
  label0->Justify =  (GtkJustification) 2;
  hbox2->Add(label0,0,1,1,0);
  gtk_window_position(GTK_WINDOW(Window()),GTK_WIN_POS_CENTER);
  EventConnect(canvas0,"button_press_event",
	       &VDKBAboutForm::OnCanvas0ButtonPress);

}

/*
main form setup
*/
void
VDKBAboutForm::Setup(void)
{
  GUISetup();
  // put your code below here
  sprintf(version,"VDK %d.%d.%d - Gtk+ %d.%d.%d - glib %d.%d.%d",
  	  VDK_VERSION_MAJOR,
  	  VDK_VERSION_MINOR,
  	  VDK_REVISION,
  	  gtk_major_version,
  	  gtk_minor_version,
  	  gtk_micro_version,
  	  glib_major_version,
  	  glib_minor_version,
  	  glib_micro_version);
  label0->Caption = version;
  // canvas settings
  canvas0->NormalBackground = clIvory;
  canvas0->Foreground = VDKRgb("navyblue");
  canvas0_font = new VDKFont(this,"helvetica bold 10");
  if((GdkFont*) *canvas0_font)
    {
      canvas0->Font = canvas0_font;
      showed_textW = canvas0_font->Width(showed_text);
      fontH = canvas0_font->Height("ABCDEFGHI");
    }
  else
  canvas0_font = NULL;
  // timer settings (does not start here - last arg = false)
  timer = new VDKTimer(this,200,false);
 
  // load cpu info
  /*
  cpuinfo = new char[4096];
  FILE* fp;
  fp = popen("cat /proc/cpuinfo","r");
  if( fp != NULL)
    { 
      memset(cpuinfo,'\0',4096);
      fread(cpuinfo,sizeof(char),4096,fp); 
      pclose(fp);
      char* p = cpuinfo;
      for(;*p;p++)
      if(*p == '\n')
      *p = ' ';
      printf("\n%s",cpuinfo);
      fflush(stdout);
    }
  */
}

/*
main form constructor
*/
VDKBAboutForm::VDKBAboutForm(VDKForm* owner, char* title):
	VDKForm(owner,title,v_box,GTK_WINDOW_POPUP)
{
}

/*
main form destructor
*/
VDKBAboutForm::~VDKBAboutForm()
{
}

/*
*/
bool
VDKBAboutForm::OnTimer(VDKObject*)
{
  int x = canvasLength-counter*6;
  canvas0->Clear();
  canvas0->DrawString(x,canvas0_font ? fontH : 16, showed_text);
  canvas0->Redraw();
  if(abs(x) >= showed_textW)
    counter = 0;
  else
    counter++;
   return true;
}

/*
 */
bool
VDKBAboutForm::Oncustombutton0Click(VDKObject* sender)
{
  Close();
  return true;
}

/*
 */
void
VDKBAboutForm::OnShow(VDKForm* sender)
{
  VDKPoint cs = canvas0->Usize;
  canvasLength = cs.x;
  timer->Start();
  return;
}

/*
 */
bool
VDKBAboutForm::CanClose(void)
{
  counter = 0;
  timer->Stop();
  if(cpuinfo)
    {
      delete[] cpuinfo;
      cpuinfo = NULL;
    }
  return true;
}