Commit 35e6875a authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added progress window for all long export operations.

parent 5b26b61f
......@@ -2,100 +2,6 @@
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="ExportDialog">
<property name="width_request">360</property>
<property name="height_request">200</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Export progress</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label43">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Exporting file</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">12</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="ExportProgress">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">12</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label42">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
</action-widgets>
</object>
<object class="GtkImage" id="ImageApplyControlVar">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -211,6 +117,101 @@
<property name="can_focus">False</property>
<property name="pixbuf">icons/panel-left.png</property>
</object>
<object class="GtkDialog" id="LongPollDialog">
<property name="width_request">360</property>
<property name="height_request">200</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Progress</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="ActivityMain">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Progress</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">12</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="LongPollProgress">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">12</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ActivitySub">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Initialising</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
</action-widgets>
</object>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">1000</property>
<property name="value">1</property>
......
This diff is collapsed.
......@@ -16,6 +16,7 @@
#include "vis.h"
#include "function.h"
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -25,15 +26,24 @@
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _ExportBitmapPersist ExportBitmapPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
ExportBitmapPersist * NewExportBitmapPersist (char const * szFilename, char const * szType, int nHeight, int nWidth, double fTimeStart, double fTimeEnd, int nFrames, VisPersist * psVisData);
void DeleteExportBitmapPersist (ExportBitmapPersist * psExportBitmapData);
bool ExportBitmapFile (char const * szFilename, char const * szType, int nHeight, int nWidth, VisPersist * psVisData);
bool ExportBitmapMemory (gchar ** ppcBuffer, gsize * puSize, char const * szType, int nHeight, int nWidth, VisPersist * psVisData);
bool ExportBitmapAnimated (char const * szFilename, char const * szType, int nHeight, int nWidth, double fTimeStart, double fTimeEnd, int nFrames, VisPersist * psVisData);
bool ExportStartAnimatedBitmap (LongPollPersist * psLongPollData, void * psData);
bool ExportStepAnimatedBitmap (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishAnimatedBitmap (LongPollPersist * psLongPollData, void * psData);
bool ExportCancelAnimatedBitmap (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
This diff is collapsed.
......@@ -16,6 +16,7 @@
#include "vis.h"
#include "function.h"
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -25,14 +26,23 @@
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _ExportPLYPersist ExportPLYPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
ExportPLYPersist * NewExportPLYPersist (char const * szFilename, bool boBinary, bool boScreenCoords, bool boExportAlpha, float fMultiplier, double fScale, double fTimeStart, double fTimeEnd, int nFrames, VisPersist * psVisData);
void DeleteExportPLYPersist (ExportPLYPersist * psExportPLYData);
bool ExportModelPLY (char const * szFilename, bool boBinary, bool boScreenCoords, bool boExportAlpha, double fMultiplier, double fScale, GSList const * const psFunctions);
bool ExportModelAnimatedPLY (char const * szFilename, bool boBinary, bool boScreenCoords, bool boExportAlpha, float fMultiplier, double fScale, double fTimeStart, double fTimeEnd, int nFrames, GSList const * const psFunctions);
bool ExportStartAnimatedPLY (LongPollPersist * psLongPollData, void * psData);
bool ExportStepAnimatedPLY (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishAnimatedPLY (LongPollPersist * psLongPollData, void * psData);
bool ExportCancelAnimatedPLY (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
This diff is collapsed.
......@@ -16,6 +16,7 @@
#include "vis.h"
#include "function.h"
#include "longpoll.h"
///////////////////////////////////////////////////////////////////
// Defines
......@@ -25,14 +26,24 @@
///////////////////////////////////////////////////////////////////
// Structures and enumerations
typedef struct _ExportSTLPersist ExportSTLPersist;
///////////////////////////////////////////////////////////////////
// Global variables
///////////////////////////////////////////////////////////////////
// Function prototypes
ExportSTLPersist * NewExportSTLPersist (char const * szFilename, bool boBinary, bool boScreenCoords, float fMultiplier, double fScale, double fTimeStart, double fTimeEnd, int nFrames, VisPersist * psVisData);
void DeleteExportSTLPersist (ExportSTLPersist * psExportSTLData);
bool ExportModelSTL (char const * szFilename, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, GSList const * const psFunctions);
bool ExportModelAnimatedSTL (char const * szFilename, bool boBinary, bool boScreenCoords, float fMultiplier, double fScale, double fTimeStart, double fTimeEnd, int nFrames, GSList const * const psFunctions);
bool ExportStartAnimatedSTL (LongPollPersist * psLongPollData, void * psData);
bool ExportStepAnimatedSTL (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishAnimatedSTL (LongPollPersist * psLongPollData, void * psData);
bool ExportCancelAnimatedSTL (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......
......@@ -30,11 +30,11 @@
// Structures and enumerations
struct _ExportSVXPersist {
GString * szFilename;
int nResolution;
int nSlice;
struct zip * psZipArchive;
VisPersist * psVisData;
char const * szFilename;
};
///////////////////////////////////////////////////////////////////
......@@ -59,16 +59,18 @@ ExportSVXPersist * NewExportSVXPersist (char const * szFilename, int nResolution
psExportSVXData = g_new0 (ExportSVXPersist, 1);
psExportSVXData->szFilename = g_string_new (szFilename);
psExportSVXData->nResolution = nResolution;
psExportSVXData->nSlice = 0;
psExportSVXData->psZipArchive = NULL;
psExportSVXData->psVisData = psVisData;
psExportSVXData->szFilename = "/home/flypig/test.svx";
return psExportSVXData;
}
void DeleteExportSVXPersist (ExportSVXPersist * psExportSVXData) {
g_string_free (psExportSVXData->szFilename, TRUE);
g_free (psExportSVXData);
}
......@@ -82,27 +84,6 @@ void FreePixelBufferSVX (guchar * pixels, gpointer data) {
g_free (pixels);
}
bool ExportModelSVX (char const * szFilename, int nResolution, VisPersist * psVisData) {
bool boSuccess = TRUE;
/*
ExportSVX sExport;
boSuccess = ExportStartSVX (szFilename, nResolution, NULL, psVisData, & sExport);
if (boSuccess) {
while ((!sExport.boDone) && (boSuccess == TRUE)) {
boSuccess = ExportStepSVX (& sExport);
}
}
if (boSuccess) {
boSuccess = ExportFinishSVX (& sExport);
}
*/
return boSuccess;
}
bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData) {
ExportSVXPersist * psExportSVXData = (ExportSVXPersist *)psData;
bool boSuccess;
......@@ -118,13 +99,15 @@ bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData) {
boSuccess = TRUE;
LongPollSetProgress (0.0f, psLongPollData);
LongPollSetActivityMain ("Exporting SVX voxel model", psLongPollData);
LongPollSetActivitySub (psLongPollData, "Initialising");
psExportSVXData->nSlice = 0;
// Check whether the file exists and delete it if it does
nResult = access (psExportSVXData->szFilename, F_OK);
nResult = access (psExportSVXData->szFilename->str, F_OK);
if (nResult == 0) {
nResult = remove (psExportSVXData->szFilename);
nResult = remove (psExportSVXData->szFilename->str);
if (nResult != 0) {
printf ("Error deleting existing file.");
boSuccess = FALSE;
......@@ -133,7 +116,7 @@ bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData) {
if (boSuccess) {
// Create the archive
psExportSVXData->psZipArchive = zip_open (psExportSVXData->szFilename, (ZIP_CREATE), & nError);
psExportSVXData->psZipArchive = zip_open (psExportSVXData->szFilename->str, (ZIP_CREATE), & nError);
if (psExportSVXData->psZipArchive == NULL) {
uErrorLength = zip_error_to_str (NULL, 0, nError, errno);
......@@ -195,6 +178,7 @@ bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData) {
boSuccess = TRUE;
fProgress = (float)psExportSVXData->nSlice / (float)psExportSVXData->nResolution;
LongPollSetProgress (fProgress, psLongPollData);
LongPollSetActivitySub (psLongPollData, "Exporting slice %d", psExportSVXData->nSlice);
nChannels = 1;
......@@ -258,8 +242,7 @@ bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData) {
// We're done with the PNG data, so we can close the stream
recclose (hFile);
printf ("Output slice %d out of %d.\n", (psExportSVXData->nSlice + 1), psExportSVXData->nResolution);
//printf ("Output slice %d out of %d.\n", (psExportSVXData->nSlice + 1), psExportSVXData->nResolution);
}
else {
printf ("Couldn't allocate memory for voxel slice.\n");
......@@ -271,6 +254,7 @@ bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData) {
psExportSVXData->nSlice++;
if (psExportSVXData->nSlice >= psExportSVXData->nResolution) {
LongPollSetActivitySub (psLongPollData, "Compressing");
LongPollDone (psLongPollData);
}
......@@ -286,7 +270,7 @@ bool ExportFinishSVX (LongPollPersist * psLongPollData, void * psData) {
LongPollSetProgress (1.0f, psLongPollData);
// Close the archive
printf ("Compressing (this may take some time).\n");
//printf ("Compressing (this may take some time).\n");
nError = zip_close (psExportSVXData->psZipArchive);
if (nError < 0) {
......@@ -299,6 +283,20 @@ bool ExportFinishSVX (LongPollPersist * psLongPollData, void * psData) {
return boSuccess;
}
bool ExportCancelSVX (LongPollPersist * psLongPollData, void * psData) {
ExportSVXPersist * psExportSVXData = (ExportSVXPersist *)psData;
// Discard any changes
zip_discard (psExportSVXData->psZipArchive);
DeleteExportSVXPersist (psExportSVXData);
return FALSE;
}
bool ExportManifestSVX (Recall * hFile, int nResolution, VisPersist * psVisData) {
float fSize;
double afRange[6];
......
......@@ -37,11 +37,12 @@ typedef struct _ExportSVXPersist ExportSVXPersist;
ExportSVXPersist * NewExportSVXPersist (char const * szFilename, int nResolution, VisPersist * psVisData);
void DeleteExportSVXPersist (ExportSVXPersist * psExportSVXData);
bool ExportModelSVX (char const * szFilename, int nResolution, VisPersist * psVisData);
void FilledCuboidSliceSVX (unsigned char * pcData, int nResolution, int nChannels, Vector3 * avCorners, float fZSlice);
bool ExportStartSVX (LongPollPersist * psLongPollData, void * psData);
bool ExportStepSVX (LongPollPersist * psLongPollData, void * psData);
bool ExportFinishSVX (LongPollPersist * psLongPollData, void * psData);
bool ExportCancelSVX (LongPollPersist * psLongPollData, void * psData);
///////////////////////////////////////////////////////////////////
......
......@@ -201,7 +201,6 @@ static gboolean DocumentationShow (GtkWidget * psWidget, gpointer psData);
static gboolean HomepageShow (GtkWidget * psWidget, gpointer psData);
void SetMaterialFill (bool boMaterialFill, FunctyPersist * psFunctyData);
static void ToggleMaterialFill (GtkWidget * psWidget, gpointer psData);
static gboolean TestProgress (GtkWidget * psWidget, gpointer psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......@@ -3198,6 +3197,7 @@ static gboolean ExportFileSVXPress (GtkWidget * psWidget, gpointer psData) {
GtkWidget * psOptionsFile;
GtkWidget * psWidgetAdd;
GtkAdjustment * psAdjustment;
ExportSVXPersist * psExportSVXData;
psFilterSVX = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterSVX, "*.svx");
......@@ -3255,7 +3255,9 @@ static gboolean ExportFileSVXPress (GtkWidget * psWidget, gpointer psData) {
szFilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (psDialogue));
// Actually perform the model export
boExported = ExportModelFileSVX (szFilename, psFunctyData->nVoxelResolution, psFunctyData->psVisData);
gtk_widget_hide (psDialogue);
psExportSVXData = NewExportSVXPersist (szFilename, psFunctyData->nVoxelResolution, psFunctyData->psVisData);
boExported = LongPoll (psFunctyData->psXML, psExportSVXData, ExportStartSVX, ExportStepSVX, ExportFinishSVX, ExportCancelSVX);
if (boExported) {
g_string_assign (psFunctyData->szExportModelNameSVX, szFilename);
......@@ -3302,6 +3304,7 @@ static gboolean ExportAnimFilePLYPress (GtkWidget * psWidget, gpointer psData) {
GtkWidget * psAlpha;
GtkWidget * psWidgetAdd;
GtkAdjustment * psAdjustment;
ExportPLYPersist * psExportPLYData;
psFilterAnim = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterAnim, "*.zip");
......@@ -3433,7 +3436,9 @@ static gboolean ExportAnimFilePLYPress (GtkWidget * psWidget, gpointer psData) {
szFilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (psDialogue));
// Actually perform the model export
boExported = ExportModelFileAnimatedPLY (szFilename, psFunctyData->boBinary, psFunctyData->boExportScreen, psFunctyData->boExportAlpha, psFunctyData->fExportMultiplier, psFunctyData->fExportScale, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
gtk_widget_hide (psDialogue);
psExportPLYData = NewExportPLYPersist (szFilename, psFunctyData->boBinary, psFunctyData->boExportScreen, psFunctyData->boExportAlpha, psFunctyData->fExportMultiplier, psFunctyData->fExportScale, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
boExported = LongPoll (psFunctyData->psXML, psExportPLYData, ExportStartAnimatedPLY, ExportStepAnimatedPLY, ExportFinishAnimatedPLY, ExportCancelAnimatedPLY);
if (boExported) {
g_string_assign (psFunctyData->szExportAnimName, szFilename);
......@@ -3479,6 +3484,7 @@ static gboolean ExportAnimFileSTLPress (GtkWidget * psWidget, gpointer psData) {
GtkWidget * psOptionsAnim;
GtkWidget * psWidgetAdd;
GtkAdjustment * psAdjustment;
ExportSTLPersist * psExportSTLData;
psFilterAnim = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterAnim, "*.zip");
......@@ -3605,7 +3611,9 @@ static gboolean ExportAnimFileSTLPress (GtkWidget * psWidget, gpointer psData) {
szFilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (psDialogue));
// Actually perform the model export
boExported = ExportModelFileAnimatedSTL (szFilename, psFunctyData->boBinary, psFunctyData->boExportScreen, psFunctyData->fExportMultiplier, psFunctyData->fExportScale, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
gtk_widget_hide (psDialogue);
psExportSTLData = NewExportSTLPersist (szFilename, psFunctyData->boBinary, psFunctyData->boExportScreen, psFunctyData->fExportMultiplier, psFunctyData->fExportScale, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
boExported = LongPoll (psFunctyData->psXML, psExportSTLData, ExportStartAnimatedSTL, ExportStepAnimatedSTL, ExportFinishAnimatedSTL, ExportCancelAnimatedSTL);
if (boExported) {
g_string_assign (psFunctyData->szExportAnimName, szFilename);
......@@ -3810,6 +3818,7 @@ static gboolean ExportAnimFilePNGPress (GtkWidget * psWidget, gpointer psData) {
GtkAdjustment * psAdjustment;
GtkWidget * psAlign;
BitmapSize sSizeWidgets;
ExportBitmapPersist * psExportBitmapData;
psFilterAnim = gtk_file_filter_new ();
gtk_file_filter_add_pattern (psFilterAnim, "*.zip");
......@@ -3965,7 +3974,9 @@ static gboolean ExportAnimFilePNGPress (GtkWidget * psWidget, gpointer psData) {
szFilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (psDialogue));
// Actually perform the model export
boExported = ExportBitmapFileAnimatedPNG (szFilename, psFunctyData->nBitmapHeight, psFunctyData->nBitmapWidth, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
gtk_widget_hide (psDialogue);
psExportBitmapData = NewExportBitmapPersist (szFilename, "png", psFunctyData->nBitmapHeight, psFunctyData->nBitmapWidth, psFunctyData->fExportTimeStart, psFunctyData->fExportTimeEnd, psFunctyData->nExportFrames, psFunctyData->psVisData);
boExported = LongPoll (psFunctyData->psXML, psExportBitmapData, ExportStartAnimatedBitmap, ExportStepAnimatedBitmap, ExportFinishAnimatedBitmap, ExportCancelAnimatedBitmap);
if (boExported) {
g_string_assign (psFunctyData->szExportAnimName, szFilename);
......@@ -4138,7 +4149,6 @@ int main (int argc, char *argv[]) {
g_signal_connect (psWidget, "clicked", G_CALLBACK (PlotFunctionCancel), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "Open"));
g_signal_connect (psWidget, "clicked", G_CALLBACK (LoadFilePress), (gpointer)psFunctyData);
//g_signal_connect (psWidget, "clicked", G_CALLBACK (TestProgress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "SaveAs"));
g_signal_connect (psWidget, "clicked", G_CALLBACK (SaveFilePress), (gpointer)psFunctyData);
psWidget = GTK_WIDGET (gtk_builder_get_object(psFunctyData->psXML, "ExportModelPLY"));
......@@ -4559,16 +4569,6 @@ gchar * GetTextViewText (GtkWidget * psTextView) {
return szText;
}
static gboolean TestProgress (GtkWidget * psWidget, gpointer psData) {
FunctyPersist * psFunctyData = (FunctyPersist * )psData;
ExportSVXPersist * psExportSVXData;
psExportSVXData = NewExportSVXPersist ("/home/flypig/test.svx", 256, psFunctyData->psVisData);
LongPoll (psFunctyData->psXML, psExportSVXData, ExportStartSVX, ExportStepSVX, ExportFinishSVX, NULL);
return TRUE;
}
......@@ -24,6 +24,7 @@
struct _LongPollPersist {
bool boDone;
bool boCancelled;
float fProgress;
VisPersist * psVisData;
GtkBuilder * psXML;
......@@ -46,6 +47,7 @@ struct _LongPollPersist {
static gboolean LongPollTimeout (gpointer psData);
bool LongPollStart (LongPollPersist * psLongPollData);
void LongPollTimeoutDestroyNotify (gpointer psData);
///////////////////////////////////////////////////////////////////
// Function definitions
......@@ -56,6 +58,7 @@ LongPollPersist * NewLongPollPersist (void) {
psLongPollData = g_new0 (LongPollPersist, 1);
psLongPollData->boDone = FALSE;
psLongPollData->boCancelled = FALSE;
psLongPollData->fProgress = 0.0f;
psLongPollData->psXML = NULL;
psLongPollData->psData = NULL;
......@@ -93,26 +96,44 @@ bool LongPoll (GtkBuilder * psXML, void * psData, LongPollCallback pmStart, Long
bool LongPollStart (LongPollPersist * psLongPollData) {
GtkDialog * psDialog;
GtkWindow * psParent;
GtkWidget * psWidget;
GtkWidget * psProgress;
int nResult;
bool boSuccess;
boSuccess = TRUE;
psParent = GTK_WINDOW (gtk_builder_get_object (psLongPollData->psXML, "MainWindow"));
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "ExportDialog"));
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "LongPollDialog"));
gtk_window_set_transient_for (GTK_WINDOW (psDialog), psParent);
psWidget = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ActivityMain"));
gtk_label_set_text (GTK_LABEL (psWidget), "");
psWidget = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ActivitySub"));
gtk_label_set_text (GTK_LABEL (psWidget), "Working");
psProgress = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "LongPollProgress"));
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (psProgress), 0.0f);
if (psLongPollData->pmStart != NULL) {
psLongPollData->pmStart (psLongPollData, psLongPollData->psData);
boSuccess = psLongPollData->pmStart (psLongPollData, psLongPollData->psData);
}
/* int nTimeoutID = */ g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, LONGPOLL_TIMEOUT, LongPollTimeout, psLongPollData, NULL);
/* int nTimeoutID = */ g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, LONGPOLL_TIMEOUT, LongPollTimeout, psLongPollData, LongPollTimeoutDestroyNotify);
nResult = gtk_dialog_run (GTK_DIALOG (psDialog));
printf ("Dialogue result: %d\n", nResult);
gtk_widget_hide (GTK_WIDGET (psDialog));
return TRUE;
if ((nResult == 0) || (nResult == -4)) {
boSuccess = FALSE;
if (psLongPollData->pmCancel != NULL) {
boSuccess = psLongPollData->pmCancel (psLongPollData, psLongPollData->psData);
}
psLongPollData->boCancelled = TRUE;
}
return boSuccess;
}
static gboolean LongPollTimeout (gpointer psData) {
......@@ -120,34 +141,52 @@ static gboolean LongPollTimeout (gpointer psData) {
bool boContinue;
GtkWidget * psProgress;
GtkDialog * psDialog;
bool boResult;
boContinue = TRUE;
boResult = TRUE;
if (psLongPollData->pmStep != NULL) {
psLongPollData->pmStep (psLongPollData, psLongPollData->psData);
}
psProgress = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "LongPollProgress"));
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (psProgress), psLongPollData->fProgress);
psProgress = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ExportProgress"));
boContinue = (!psLongPollData->boDone) && (!psLongPollData->boCancelled);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (psProgress), psLongPollData->fProgress);
if (!psLongPollData->boCancelled) {
if (!psLongPollData->boDone) {
if (psLongPollData->pmStep != NULL) {
boResult = psLongPollData->pmStep (psLongPollData, psLongPollData->psData);
}
}
else {
if (psLongPollData->pmFinish != NULL) {
boResult = psLongPollData->pmFinish (psLongPollData, psLongPollData->psData);
}
boContinue = !psLongPollData->boDone;
if (!boContinue) {
if (psLongPollData->pmFinish != NULL) {
psLongPollData->pmFinish (psLongPollData, psLongPollData->psData);
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "LongPollDialog"));
gtk_dialog_response (psDialog, 1);
}
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "ExportDialog"));
if (boResult == FALSE) {
psDialog = GTK_DIALOG (gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error occured during operation"));
gtk_dialog_run (psDialog);
gtk_widget_destroy (GTK_WIDGET (psDialog));
DeleteLongPollPersist (psLongPollData);
psDialog = GTK_DIALOG (gtk_builder_get_object (psLongPollData->psXML, "LongPollDialog"));
gtk_dialog_response (psDialog, -1);
gtk_dialog_response (psDialog, 0);
boContinue = FALSE;
}
}
return boContinue;
}
void LongPollTimeoutDestroyNotify (gpointer psData) {
LongPollPersist * psLongPollData = (LongPollPersist *)psData;
DeleteLongPollPersist (psLongPollData);
}
void LongPollSetProgress (float fProgress, LongPollPersist * psLongPollData) {
psLongPollData->fProgress = fProgress;
}
......@@ -156,3 +195,36 @@ void LongPollDone (LongPollPersist * psLongPollData) {
psLongPollData->boDone = TRUE;
}
void LongPollSetActivityMain (char const * const szText, LongPollPersist * psLongPollData) {
GtkWidget * psWidget;
psWidget = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ActivityMain"));
gtk_label_set_text (GTK_LABEL (psWidget), szText);
}
void LongPollSetActivitySub (LongPollPersist * psLongPollData, const char * format, ...) {
GtkWidget * psWidget;
GString * szText;
va_list args;
va_start (args, format);
// Create a temporary string to store the result in
szText = g_string_new ("");
g_string_vprintf (szText, format, args);
va_end (args);
psWidget = GTK_WIDGET (gtk_builder_get_object (psLongPollData->psXML, "ActivitySub"));
gtk_label_set_text (GTK_LABEL (psWidget), szText->str);
// Free up the temporary copy of the data