/* * * ProLinga-Run * * Copyright (C) 2002-2008 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Run. * * ProLinga-Run is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Run 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Run. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RunCommon.h" #include #include "DataRef.hpp" #include "Widget.hpp" GtkWidget *LocateProgressBar(GtkWidget *wdg, const char *wdgName) { GtkWidget *curWdg, *pbWdg = NULL; GList *wdgList; int i, lengthWdgList; wdgList = gtk_container_get_children(GTK_CONTAINER(wdg)); lengthWdgList = g_list_length(wdgList); for (i = 0; i < lengthWdgList; i++) { curWdg = GTK_WIDGET(g_list_nth_data(wdgList, i)); //printf("WIDGET : %s NAME : %s\n", G_OBJECT_TYPE_NAME(G_OBJECT(curWdg)), gtk_widget_get_name(curWdg)); if (strcmp(G_OBJECT_TYPE_NAME(G_OBJECT(curWdg)), WDG_PROGRESSBAR) == 0) { if (strcmp(wdgName, (char *)gtk_widget_get_name(curWdg)) == 0) return curWdg; } if (GTK_IS_CONTAINER(curWdg)) { pbWdg = LocateProgressBar(curWdg, wdgName); if (pbWdg != NULL) return pbWdg; } } /* Return */ return pbWdg; } /* Command : PROGRESS */ /* Syntax : PROGRESS BOUNCE progress_bar_ref STEP numeric */ /* Syntax : PROGRESS BOUNCE progress_bar_ref UPDATE */ /* Syntax : PROGRESS FRACTION progress_bar_ref VALUE numeric */ /* Syntax : PROGRESS TEXT progress_bar_ref VALUE data_ref [data_ref...] */ void CmdProgress(char **argList, int argHits, bool isMainThread, GtkWidget *outputScreen) { GtkWidget *pbWdg = NULL; int i; char pbName[64], pbLabel[255], retValue[255]; double fraction, step; /* Get name of progress bar */ getDataRef(argList[2], isMainThread, pbName, false); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Find progress bar */ pbWdg = LocateProgressBar(outputScreen, pbName); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* If no progress bar found, exit */ if (pbWdg == NULL) return; /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Process sub command */ if (strcmp(argList[1], "BOUNCE") == 0) { if (strcmp(argList[3], "STEP") == 0) { step = atof(getDataRef(argList[4], isMainThread, retValue, false)); gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(pbWdg), step); } else if (strcmp(argList[3], "UPDATE") == 0) { gtk_progress_bar_pulse(GTK_PROGRESS_BAR(pbWdg)); } } else if (strcmp(argList[1], "FRACTION") == 0) { fraction = atof(getDataRef(argList[4], isMainThread, retValue, false)); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbWdg), fraction); } else if (strcmp(argList[1], "LABEL") == 0) { /* Concatenate 1 big string from arguments */ for (i = 4; i <= argHits; i++) { getDataRefRaw(argList[i], isMainThread, retValue, false); if (i == 4) strcpy(pbLabel, retValue); else strcat(pbLabel, retValue); } gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbWdg), pbLabel); } else printf("sub command not (yet) implemented.\n"); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } }