00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <locale.h>
00029 #include <libintl.h>
00030
00031
00032 #include "../pixmaps/gxsmlogo.xpm"
00033
00034 #include "gxsm_app.h"
00035 #include "gxsm_menudef.h"
00036
00037 #include "version.h"
00038 #include "glbvars.h"
00039
00040 #include "unit.h"
00041 #include "pcs.h"
00042
00043 #include "xsmtypes.h"
00044 #include "surface.h"
00045 #include "tips_dialog.h"
00046 #include "plugin_ctrl.h"
00047
00048
00049
00050
00051
00052 App::App(int restarted)
00053 {
00054 XSM_DEBUG(DBG_L2, "App::App" );
00055
00056 app = NULL;
00057
00058
00059 channelselector = NULL;
00060 monitorcontrol = NULL;
00061 spm_control = NULL;
00062 xsm = NULL;
00063
00064
00065 RemoteEntryList = NULL;
00066 RemoteActionList = NULL;
00067 remotecontrol = NULL;
00068
00069
00070 GxsmPlugins = NULL;
00071 PluginNotifyOnSPMRange = NULL;
00072 PluginNotifyOnStartScan = NULL;
00073 PluginNotifyOnStopScan = NULL;
00074 PluginNotifyOnCDFLoad = NULL;
00075 PluginNotifyOnCDFSave = NULL;
00076 PluginNotifyOnLoadFile = NULL;
00077 PluginNotifyOnSaveFile = NULL;
00078
00079 PluginCallGetNCInfo = NULL;
00080 PluginCallPrinter = NULL;
00081 PluginCallMkicons = NULL;
00082
00083
00084 nodestroy = TRUE;
00085 }
00086
00087 App::~App(){
00088 SetStatus(N_("App::~App: Closing Application object now."));
00089 XSM_DEBUG(DBG_L2, "App::~App: Closing Application object now..." );
00090
00091
00092 reload_gxsm_plugins( TRUE );
00093
00094 delete channelselector;
00095 delete monitorcontrol;
00096
00097 delete spm_control;
00098 delete xsm;
00099 check_events();
00100 XSM_DEBUG(DBG_L2, "App::~App: done." );
00101 }
00102
00103 void App::build_gxsm(){
00104 XSM_DEBUG(DBG_L2, "App::build_gxsm" );
00105
00106
00107 app = gnome_app_new (PACKAGE, _("Gxsm - STM/AFM/SPA-LEED..."));
00108
00109 gtk_widget_realize (app);
00110 gtk_signal_connect (GTK_OBJECT (app), "delete_event",
00111 GTK_SIGNAL_FUNC (file_exit_callback),
00112 NULL);
00113
00114 gnome_window_icon_set_from_file (GTK_WINDOW (app),
00115 GNOME_ICONDIR"/GxsmBWlogoTransparentColor.png");
00116
00117 GnomeAppServiceSetApp(app);
00118
00119 GxsmSplash();
00120
00121
00122 gnome_app_create_menus (GNOME_APP (app), main_menu);
00123 gxsmmenu = (GNOME_APP (app))->menubar;
00124
00125
00126 gnome_app_create_toolbar (GNOME_APP (app), main_toolbar);
00127
00128
00129 appbar = gnome_appbar_new(TRUE, TRUE, GNOME_PREFERENCES_NEVER);
00130 gnome_app_set_statusbar(GNOME_APP (app), GTK_WIDGET (appbar));
00131
00132
00133 gtk_widget_show (GTK_WIDGET (appbar));
00134 gtk_widget_show (GTK_WIDGET (app));
00135
00136 XSM_DEBUG(DBG_L2, "App::build_gxsm - starting up" );
00137 SetStatus(N_("Starting GXSM..."));
00138
00139
00140 XSM_DEBUG(DBG_L2, "App::build_gxsm - reading config" );
00141 SetStatus(N_("Reading User Config"));
00142
00143 GnomeResPreferences *pref = gnome_res_preferences_new (xsm_res_def);
00144 gnome_res_read_user_config (pref);
00145 gnome_res_destroy (pref);
00146
00147 ClearStatus();
00148
00149
00150 XSM_DEBUG(DBG_L2, "App::build_gxsm - tooltips install" );
00151 if(xsmres.menutooltips)
00152 gnome_app_install_menu_hints(GNOME_APP (app), main_menu);
00153
00154
00155 XSM_DEBUG(DBG_L2, "App::build_gxsm - xsm = new Surface" );
00156 SetStatus(N_("Generating Surface Object..."));
00157 xsm = new Surface ();
00158
00159
00160 XSM_DEBUG(DBG_L2, "App::build_gxsm - Scanning for PlugIns...");
00161 SetStatus(N_("Scanning for GXSM Plugins..."));
00162 if( !xsmres.disableplugins )
00163 reload_gxsm_plugins();
00164
00165
00166 XSM_DEBUG(DBG_L2, "App::build_gxsm - main control window" );
00167 main_control = create_control ();
00168
00169
00170
00171 XSM_DEBUG(DBG_L2, "App::build_gxsm - DnD setup" );
00172 configure_drop_on_widget(main_control);
00173
00174
00175
00176
00177 XSM_DEBUG(DBG_L2, "App::build_gxsm - attach control" );
00178 spm_control = NULL;
00179 xsm->SetModeFlg(MODE_SETSTEPS);
00180 if(IS_SPALEED_CTRL)
00181
00182 spm_control = create_spa_control ();
00183 else
00184
00185 spm_control = create_spm_control ();
00186
00187
00188 XSM_DEBUG(DBG_L2, "App::build_gxsm - AS control" );
00189 as_control = create_as_control ();
00190
00191
00192 XSM_DEBUG(DBG_L2, "App::build_gxsm - UI control" );
00193 ui_control = create_ui_control ();
00194
00195
00196 gnome_app_set_contents ( GNOME_APP (app), main_control);
00197 gtk_widget_show (spm_control);
00198
00199 XSM_DEBUG(DBG_L2, "App::build_gxsm - Monitor");
00200
00201 monitorcontrol = new MonitorControl();
00202
00203 XSM_DEBUG(DBG_L2, "App::build_gxsm - Channelselector");
00204 channelselector = new ChannelSelector();
00205
00206
00207
00208
00209
00210
00211
00212
00213 monitorcontrol->SetResName ("WindowMonitorControl", "false", xsmres.geomsave);
00214 channelselector->SetResName ("WindowChannelSelector", "true", xsmres.geomsave);
00215
00216
00217 XSM_DEBUG(DBG_L2, "App::build_gxsm - update all entries");
00218 spm_update_all(-xsm->data.display.ViewFlg);
00219 monitorcontrol->LogEvent("GXSM", "startup");
00220
00221
00222 XSM_DEBUG(DBG_L2, "App::build_gxsm - menu toggels setup");
00223 SetupToggleMenuItem(gxsmmenu, N_("View/Autozoom"), TRUE);
00224
00225 XSM_DEBUG(DBG_L2, "App::build_gxsm - done.");
00226 }
00227
00228
00229
00230
00231 gint App::Gxsm_Plugin_Check (const gchar *category){
00232 if( category ){
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 gint phard, mhard, pinst, minst;
00252 gchar *pht=g_strconcat("+", xsmres.HardwareType, "HARD", NULL);
00253 gchar *mht=g_strconcat("-", xsmres.HardwareType, "HARD", NULL);
00254 gchar *pit=g_strconcat("+", xsmres.InstrumentType, NULL);
00255 gchar *mit=g_strconcat("-", xsmres.InstrumentType, NULL);
00256
00257 if( strstr( category, pht ) || !strstr( category, "HARD") )
00258 phard = TRUE; else phard = FALSE;
00259 if( !strstr( category, mht ) || !strstr( category, "HARD") )
00260 mhard = TRUE; else mhard = FALSE;
00261
00262 if( strstr( category, pit ) || strstr( category, "+ALL") )
00263 pinst = TRUE; else pinst = FALSE;
00264 if( !strstr( category, mit ) || strstr( category, "+ALL") )
00265 minst = TRUE; else minst = FALSE;
00266
00267 g_free(pit);
00268 g_free(mit);
00269 g_free(pht);
00270 g_free(mht);
00271
00272 if((phard && mhard) && (pinst && minst))
00273 return TRUE;
00274 return FALSE;
00275 }
00276 return TRUE;
00277 }
00278
00279
00280 void App::ConnectPluginToSPMRangeEvent( void (*cbfkt)(gpointer) ){
00281 PluginNotifyOnSPMRange = g_list_prepend(PluginNotifyOnSPMRange, (gpointer) cbfkt);
00282 }
00283 void App::ConnectPluginToStartScanEvent( void (*cbfkt)(gpointer) ){
00284 PluginNotifyOnStartScan = g_list_prepend(PluginNotifyOnStartScan, (gpointer) cbfkt);
00285 }
00286 void App::ConnectPluginToStopScanEvent( void (*cbfkt)(gpointer) ){
00287 PluginNotifyOnStopScan = g_list_prepend(PluginNotifyOnStopScan, (gpointer) cbfkt);
00288 }
00289 void App::ConnectPluginToCDFLoadEvent( void (*cbfkt)(gpointer) ){
00290 PluginNotifyOnCDFLoad = g_list_prepend(PluginNotifyOnCDFLoad, (gpointer) cbfkt);
00291 }
00292 void App::ConnectPluginToCDFSaveEvent( void (*cbfkt)(gpointer) ){
00293 PluginNotifyOnCDFSave = g_list_prepend(PluginNotifyOnCDFSave, (gpointer) cbfkt);
00294 }
00295 void App::ConnectPluginToLoadFileEvent( void (*cbfkt)(gpointer) ){
00296 PluginNotifyOnLoadFile = g_list_prepend(PluginNotifyOnLoadFile, (gpointer) cbfkt);
00297 }
00298 void App::ConnectPluginToSaveFileEvent( void (*cbfkt)(gpointer) ){
00299 PluginNotifyOnSaveFile = g_list_prepend(PluginNotifyOnSaveFile, (gpointer) cbfkt);
00300 }
00301
00302 void App::ConnectPluginToGetNCInfoEvent( void (*cbfkt)(gchar *filename ) ){
00303 PluginCallGetNCInfo = cbfkt;
00304 }
00305
00306 void App::ConnectPluginToPrinterEvent( void (*cbfkt)(GtkWidget*, void*) ){
00307 PluginCallPrinter = cbfkt;
00308 }
00309
00310 void App::ConnectPluginToMkiconsEvent( void (*cbfkt)(GtkWidget*, void*) ){
00311 PluginCallMkicons = cbfkt;
00312 }
00313
00314
00315 void App::reload_gxsm_plugins( gint killflag ){
00316 gint (*gxsm_plugin_check)(const gchar *) = Gxsm_Plugin_Check;
00317 GList *PluginDirs = NULL;
00318 XSM_DEBUG(DBG_L2, "Remove/Reload Gxsm plugins" );
00319
00320
00321 if( PluginNotifyOnSPMRange ){
00322 g_list_free( PluginNotifyOnSPMRange);
00323 PluginNotifyOnSPMRange = NULL;
00324 }
00325 if( PluginNotifyOnStartScan ){
00326 g_list_free( PluginNotifyOnStartScan );
00327 PluginNotifyOnStartScan = NULL;
00328 }
00329 if( PluginNotifyOnStopScan ){
00330 g_list_free( PluginNotifyOnStopScan );
00331 PluginNotifyOnStopScan = NULL;
00332 }
00333 if( PluginNotifyOnCDFLoad ){
00334 g_list_free( PluginNotifyOnCDFLoad );
00335 PluginNotifyOnCDFLoad = NULL;
00336 }
00337 if( PluginNotifyOnCDFSave ){
00338 g_list_free( PluginNotifyOnCDFSave );
00339 PluginNotifyOnCDFSave = NULL;
00340 }
00341 if( PluginNotifyOnLoadFile ){
00342 g_list_free( PluginNotifyOnLoadFile );
00343 PluginNotifyOnLoadFile = NULL;
00344 }
00345 if( PluginNotifyOnSaveFile ){
00346 g_list_free( PluginNotifyOnSaveFile );
00347 PluginNotifyOnSaveFile = NULL;
00348 }
00349
00350 PluginCallGetNCInfo = NULL;
00351 PluginCallPrinter = NULL;
00352 PluginCallMkicons = NULL;
00353
00354
00355 xsm->reload_hardware_interface (killflag ? NULL:this);
00356
00357 if( !GxsmPlugins && killflag ){
00358 XSM_DEBUG(DBG_L2, "no GXSM plugins found, done." );
00359 return;
00360 }
00361
00362 if( GxsmPlugins ){
00363 SetStatus(N_("Removing Plugins..."));
00364 delete GxsmPlugins;
00365 GxsmPlugins = NULL;
00366 if( killflag )
00367 return;
00368
00369 XSM_DEBUG(DBG_L2, "Plugins removed" );
00370 SetStatus(N_("Plugins removed"));
00371
00372 GtkWidget *dialog = gtk_message_dialog_new
00373 (NULL,
00374 GTK_DIALOG_DESTROY_WITH_PARENT,
00375 GTK_MESSAGE_QUESTION,
00376 GTK_BUTTONS_NONE,
00377 N_("GXSM PlugIns unloaded. Reload plug-ins now?\n\n"
00378 "Yes: automatic plug-in selection\n"
00379 "All: force loading of all plug-ins\n"
00380 "No: do not load any plug-in,\n"
00381 " call 'GXSM->Reload Plugins' again\n"
00382 " to auto load plug-ins again!"));
00383 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
00384 GTK_STOCK_YES, GTK_RESPONSE_YES,
00385 N_("All"), 99,
00386 GTK_STOCK_NO, GTK_RESPONSE_NO,
00387 NULL);
00388
00389 int ret = gtk_dialog_run (GTK_DIALOG(dialog));
00390 gtk_widget_destroy (dialog);
00391
00392 switch(ret){
00393 case GTK_RESPONSE_YES : break;
00394 case 99 : gxsm_plugin_check = NULL; break;
00395 default: return;
00396 }
00397 }
00398
00399 GxsmSplash(0.01, " ", "Looking for GXSM PlugIns");
00400
00401
00402 PluginDirs = g_list_prepend
00403 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/common", NULL));
00404 PluginDirs = g_list_prepend
00405 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/math", NULL));
00406 PluginDirs = g_list_prepend
00407 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/probe", NULL));
00408 PluginDirs = g_list_prepend
00409 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/control", NULL));
00410 PluginDirs = g_list_prepend
00411 (PluginDirs, g_strconcat(PACKAGE_PLUGIN_DIR, "/scan", NULL));
00412 PluginDirs = g_list_prepend
00413 (PluginDirs, g_strconcat(g_get_home_dir(), "/.gxsm/plugins", NULL));
00414 PluginDirs = g_list_prepend
00415 (PluginDirs, g_strdup(xsmres.UserPluginPath));
00416
00417 GxsmPlugins = new gxsm_plugins(this, PluginDirs, gxsm_plugin_check);
00418
00419
00420 GList *node = PluginDirs;
00421 while(node){
00422 g_free(node->data);
00423 node = node->next;
00424 }
00425 g_list_free(PluginDirs);
00426
00427 gchar *txt = g_strdup_printf
00428 (N_("%d Plugins loaded!"), GxsmPlugins->how_many());
00429 SetStatus(txt);
00430
00431 g_free(txt);
00432
00433 GxsmSplash(-1.);
00434 }
00435
00436 void App::CallPlugin( void (*cbfkt)( gpointer ), gpointer data){
00437 (*cbfkt) ( data );
00438 }
00439
00440 void App::SignalEventToPlugins( GList *PluginNotifyList, gpointer data ){
00441 g_list_foreach( PluginNotifyList, (GFunc) CallPlugin, data);
00442 }
00443
00444
00445
00446
00447
00448 gint App::RemoveGxsmSplash(GtkWidget *widget){
00449
00450
00451
00452 gtk_widget_destroy (widget);
00453
00454
00455
00456 XsmRescourceManager xrm("GUI-global","Tips");
00457 if (xrm.GetBool("ShowTips", TRUE))
00458 tips_dialog_create ();
00459
00460 return FALSE;
00461 }
00462
00463 void App::GxsmSplash(gdouble progress, const gchar *text, const gchar* info){
00464 static GtkWidget *progress_bar = NULL;
00465 static GnomeCanvasItem *info_label = NULL;
00466 static GtkWidget *splash = NULL;
00467 GtkWidget *canvas;
00468 GdkPixbuf *img;
00469 gchar *sload;
00470 gchar *font, *font2;
00471 gchar *fontcolor, *fontcolor2;
00472 gchar *txt;
00473
00474 if (progress_bar && splash && progress > -0.2){
00475 if (progress >= 0. && progress <= 1.0)
00476 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), progress);
00477 else
00478 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar));
00479 if (text){
00480 gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), text);
00481 }
00482 if (info)
00483 gnome_canvas_item_set(info_label, "text", info, NULL);
00484 while(gtk_events_pending()) gtk_main_iteration();
00485 return;
00486 }
00487 else if (splash && progress < -0.5){
00488 XsmRescourceManager xrm("GUI-global","Splash");
00489 int ms;
00490 xrm.Get("timeout", &ms, "3000");
00491 if (ms < 100) ms = 5000;
00492 gtk_timeout_add (ms, (GtkFunction) App::RemoveGxsmSplash, splash);
00493 progress_bar = NULL;
00494 splash = NULL;
00495 return;
00496 }
00497
00498 const int ImgW = atoi(xxsmlogo_xpm[0]);
00499 const int ImgH = atoi(xxsmlogo_xpm[0]+4);
00500
00501 XsmRescourceManager xrm("GUI-global","Splash");
00502 sload = xrm.GetStr("load", "Yes");
00503 XSM_DEBUG(DBG_L5, "App::GxsmSplash: load = " << sload << "<");
00504
00505 if (!strcasecmp (sload, "yes")){
00506 font = xrm.GetStr ("font", "helvetica Bold 18");
00507 fontcolor = xrm.GetStr ("fontcolor", "blue");
00508 font2 = xrm.GetStr ("font2", "helvetica 12");
00509 fontcolor2 = xrm.GetStr ("fontcolor2", "black");
00510 txt = xrm.GetStr ("message", "STM/AFM/SPALEED...");
00511
00512 splash = gtk_window_new (GTK_WINDOW_POPUP);
00513 gtk_window_set_default_size(GTK_WINDOW(splash), ImgW, ImgH+20);
00514 gtk_window_set_title(GTK_WINDOW(splash), "GXSM Startup");
00515 gtk_widget_set_uposition (splash, (gdk_screen_width()-ImgW)/2, (gdk_screen_height()-ImgH)/2);
00516
00517 GtkWidget* vb = gtk_vbox_new (FALSE, 0);
00518 gtk_widget_show (vb);
00519 gtk_container_add (GTK_CONTAINER (splash), vb);
00520
00521 canvas = gnome_canvas_new();
00522 gnome_canvas_set_pixels_per_unit( GNOME_CANVAS(canvas), 1.);
00523 gnome_canvas_set_scroll_region( GNOME_CANVAS(canvas), -(double)ImgW/2, -(double)ImgH/2, (double)ImgW/2, (double)ImgH/2);
00524
00525 gtk_box_pack_start_defaults (GTK_BOX (vb), canvas);
00526
00527 progress_bar = gtk_progress_bar_new ();
00528 #ifdef PANGO_ELLIPSIZE_START
00529 gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (progress_bar), PANGO_ELLIPSIZE_START);
00530 #endif
00531 gtk_widget_show (progress_bar);
00532 gtk_box_pack_start (GTK_BOX (vb), progress_bar, FALSE, FALSE, 0);
00533
00534 img = gdk_pixbuf_new_from_xpm_data(xxsmlogo_xpm);
00535 gtk_object_set_data( GTK_OBJECT (splash), "splash_pixbuf", img);
00536 gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00537 gnome_canvas_pixbuf_get_type(),
00538 "pixbuf", img,
00539 "x", 0.0,
00540 "y", 0.0,
00541 "anchor", GTK_ANCHOR_CENTER,
00542 NULL);
00543 info_label = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00544 gnome_canvas_text_get_type(),
00545 "text", txt,
00546 "x", 0.0,
00547 "y", 60.0,
00548 "fill_color", "black",
00549 "font", font2,
00550 "anchor", GTK_ANCHOR_CENTER,
00551 NULL);
00552 gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00553 gnome_canvas_text_get_type(),
00554 "text", PACKAGE "-" VERSION,
00555 "x", 0.0,
00556 "y", -60.0,
00557 "fill_color", "blue",
00558 "font", font,
00559 "anchor", GTK_ANCHOR_CENTER,
00560 NULL);
00561
00562 gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS(canvas)),
00563 gnome_canvas_rect_get_type(),
00564 "x1",-(double)ImgW/2+1,
00565 "y1",-(double)ImgH/2+1,
00566 "x2",(double)ImgW/2-1,
00567 "y2",(double)ImgH/2-1,
00568 "outline_color","grey80",
00569 "width_units",4.0,
00570 NULL);
00571 g_free(font);
00572 g_free(fontcolor);
00573 g_free(txt);
00574
00575 gtk_widget_show(canvas);
00576
00577 gtk_widget_show(splash);
00578
00579 while(gtk_events_pending()) gtk_main_iteration();
00580 }
00581 }
00582