/* * * ProLinga-Run * * Copyright (C) 2002-2009 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 #include #include #include #include "RunShare.hpp" #include "RepositoryCommand.hpp" #include "DataRef.hpp" #include "CmdList.hpp" #include "LogicCommands.hpp" extern BiAppnPtr biAppnPtr; extern BiAppnDevPtr biAppnDevPtr; extern pthread_t mainThreadId; /* Datastore for List Views */ extern ListStorePtr listStorePtr; static GtkTreeSelection *cbSelection; void ResetStores(void) { /* Delete store list */ listStorePtr->deleteList(&listStorePtr); } extern "C" void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer data) { GtkListStore *storePtr; char *storeName; bool isMainThread; /* Determine if call comes from main thread */ if (pthread_equal(mainThreadId, pthread_self()) == 0) isMainThread = false; else isMainThread = true; /* Call back selection */ cbSelection = selection; /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Put selection into store object */ storePtr = GTK_LIST_STORE(gtk_tree_view_get_model(gtk_tree_selection_get_tree_view(selection))); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Get Store name */ storeName = listStorePtr->getName(listStorePtr, storePtr); /* Store selection */ listStorePtr->putSelection(&listStorePtr, storeName, selection); } ListHeader::ListHeader() { position = 0; label = NULL; dataType = LIST_TEXT; nextPtr = NULL; } ListHeader::~ListHeader() { if (label != NULL) delete label; } char *ListHeader::getValue(ListHeader *lheadPtr, const int colNo) { ListHeaderPtr curPtr; /* Check if header exists in memory */ curPtr = lheadPtr; while (curPtr != NULL) { if (curPtr->position == colNo) return curPtr->label; curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void ListHeader::putValue(ListHeader **lheadPtr, const int colNo, const char *labelText) { ListHeaderPtr curPtr, prevPtr, newPtr; /* Check if header exists in memory */ curPtr = *lheadPtr; prevPtr = NULL; while (curPtr != NULL) { if (curPtr->position == colNo) { if (curPtr->label != NULL) delete curPtr->label; curPtr->label = new char[(strlen(labelText)+1)]; strcpy(curPtr->label, labelText); return; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Create new Header List */ newPtr = new ListHeader; newPtr->position = colNo; newPtr->label = new char[(strlen(labelText)+1)]; strcpy(newPtr->label, labelText); if (prevPtr == NULL) { /* First Record */ *lheadPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } } int ListHeader::getDataType(ListHeader *lheadPtr, const int colNo) { ListHeaderPtr curPtr; /* Check if header exists in memory */ curPtr = lheadPtr; while (curPtr != NULL) { if (curPtr->position == colNo) return curPtr->dataType; curPtr = curPtr->nextPtr; } /* Return */ return 1; } void ListHeader::putDataType(ListHeader **lheadPtr, const int colNo, const int type) { ListHeaderPtr curPtr; /* Check if header exists in memory */ curPtr = *lheadPtr; while (curPtr != NULL) { if (curPtr->position == colNo) { curPtr->dataType = type; break; } curPtr = curPtr->nextPtr; } } void ListHeader::deleteList(ListHeader **lheadPtr) { ListHeaderPtr curPtr, tmpPtr; curPtr = *lheadPtr; *lheadPtr = NULL; while (curPtr != NULL) { tmpPtr = curPtr; curPtr = curPtr->nextPtr; delete tmpPtr; } } void ListHeader::printList(ListHeader *lheadPtr) const { ListHeaderPtr curPtr; curPtr = lheadPtr; while (curPtr != NULL) { printf("List Header : %d Label : %s Type : %d\n", curPtr->position, curPtr->label, curPtr->dataType); curPtr = curPtr->nextPtr; } } ListStore::ListStore() { strcpy(listName, ""); numCols = 0; sortCol = 0; sortDirection = LIST_SORTING_NONE; storePtr = NULL; startPtr = NULL; cbSelection = NULL; nextPtr = NULL; } ListStore::~ListStore() { //GtkTreeView *view; if (startPtr != NULL) { startPtr->deleteList(&startPtr); } if (cbSelection != NULL) { //printf("remove selection \n"); /* Unlink store from view */ // view = gtk_tree_selection_get_tree_view(cbSelection); // gtk_tree_view_set_model(view, NULL); //g_object_unref (G_OBJECT (cbSelection)); // gtk_tree_selection_unselect_all (cbSelection); // gtk_widget_destroy(GTK_WIDGET(view)); // storePtr = GTK_LIST_STORE(gtk_tree_view_get_model(gtk_tree_selection_get_tree_view(selection))); } if (storePtr != NULL) { //printf("remove store \n"); /* Remove store (not sure if this is enough to clean out of mem */ // gtk_list_store_clear(storePtr); g_object_unref (G_OBJECT (storePtr)); } } GtkListStore *ListStore::getValue(ListStore **listPtr, const char *name) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->storePtr; curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void ListStore::loadStore(ListStore **listPtr, const char *name, xmlDocPtr doc, const bool isMainThread) { ListStorePtr curPtr, prevPtr = NULL, newPtr; xmlNodePtr curRes; xmlXPathContextPtr ctxt; xmlXPathObjectPtr res; GtkListStore *storePtr = NULL; GType *types; GtkTreeIter iter; int cols, insHits, i, j, columnId; double f; char stm[255]; xmlChar *elementValue, *listValue; /* Prepend name with devappn name if set */ // if (strlen(biAppnDevPtr->getAppnDev()) == 0) // strcpy(extendedName, name); // else // sprintf(extendedName,"%s_%s", biAppnDevPtr->getAppnDev(), name); /* If store exist in memory, clear */ /* Empty List?*/ if (*listPtr != NULL) { curPtr = *listPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { if (prevPtr == NULL) *listPtr = curPtr->nextPtr; else prevPtr->nextPtr = curPtr->nextPtr; delete curPtr; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } } /* Create XPath environment */ ctxt = xmlXPathNewContext(doc); /* Append new record */ newPtr = new ListStore; strcpy(newPtr->listName, name); newPtr->nextPtr = NULL; /* Build the store */ /* Get Number of Columns */ res = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/ListStore/NumColumns", ctxt); cols = (int)xmlXPathCastToNumber(res); /* Get Data Types from columns */ types = new GType[cols]; /* Process Column info */ res = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader)", ctxt); insHits = (int)xmlXPathCastToNumber(res); /* Set number of columns */ newPtr->numCols = insHits; for (i = 1; i <= insHits; i++) { /* Get Column id */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnId", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); columnId = (int)xmlXPathCastToNumber(res); /* Get Column Label */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnLabel", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); /* Insert Column Header in memlist */ newPtr->putHeaderValue(&newPtr, name, columnId, (char *)xmlXPathCastToString(res)); /* Check if sort column */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/DefaultSort", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "True") == 0) { newPtr->sortCol = columnId; /* Check if sort column */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/SortDirection", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "None") == 0) newPtr->sortDirection = LIST_SORTING_NONE; else if (strcmp((char *)xmlXPathCastToString(res), "Descending") == 0) newPtr->sortDirection = LIST_SORTING_DESCENDING; else newPtr->sortDirection = LIST_SORTING_ASCENDING; } /* Get Column Type */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnType", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "Text") == 0) { newPtr->putColumnDataType(&newPtr, name, columnId, LIST_TEXT); types[(i-1)] = G_TYPE_STRING; } else { newPtr->putColumnDataType(&newPtr, name, columnId, LIST_NUMBER); types[(i-1)] = G_TYPE_DOUBLE; } } /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storePtr = gtk_list_store_newv(cols, types); gtk_list_store_clear(storePtr); GTK_LIST_STORE(storePtr)->sort_column_id = -2; /* Process List Data */ /* Loop through all rows */ i = 1; for (;;) { sprintf(stm,"/ProLinga/Repository/Command/Object/ListStore/OccurrencesListData/ListData[RowId='%d']", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); insHits = (int)res->nodesetval->nodeNr; if (insHits <= 0) break; /* Put in values */ gtk_list_store_append(storePtr, &iter); /* Get Column info */ for (j = 0; j < insHits; j++) { /* Get Column Id */ curRes = res->nodesetval->nodeTab[j]; for (curRes = curRes->xmlChildrenNode; curRes != NULL; curRes = curRes->next) { /* Column Id */ if (!xmlStrcmp(curRes->name, (const xmlChar *) "ColumnId")) { elementValue = xmlNodeListGetString(doc, curRes->xmlChildrenNode, 1); columnId = atoi((char *)elementValue); xmlFree(elementValue); } /* Value */ else if (!xmlStrcmp(curRes->name, (const xmlChar *) "Value")) listValue = xmlNodeListGetString(doc, curRes->xmlChildrenNode, 1); } /* Insert Value */ if (newPtr->getColumnDataType(newPtr, name, columnId) == LIST_TEXT) gtk_list_store_set(storePtr, &iter, (columnId - 1), (char *)listValue, -1); else { f = atof((char *)listValue); gtk_list_store_set(storePtr, &iter, (columnId - 1), f, -1); } /* Free */ xmlFree(listValue); } /* Raise Counter */ i++; } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Insert store */ newPtr->storePtr = storePtr; if (prevPtr == NULL) { /* First Record */ *listPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } /* Clean up */ // xmlFreeDoc(doc); delete types; /* Return */ // return newPtr->storePtr; } GtkListStore *ListStore::getStore(ListStore **listPtr, const char *name, const bool isMainThread) { ListStorePtr curPtr, prevPtr, newPtr; xmlDocPtr docRes; xmlNodePtr curRes; xmlXPathContextPtr ctxt; xmlXPathObjectPtr res; GtkListStore *storePtr = NULL; GType *types; GtkTreeIter iter; int cols, insHits, i, j, columnId; double f; char stm[255]; xmlChar *elementValue, *listValue; /* Check if store exists in memory */ curPtr = *listPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->storePtr; prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Check Repository */ docRes = RC_Get(biAppnPtr->getAppn(), "ListStore", name); /* Init XPath */ //xmlXPathInit(); /* Create XPath environment */ ctxt = xmlXPathNewContext(docRes); /* Append new record */ newPtr = new ListStore; strcpy(newPtr->listName, name); newPtr->nextPtr = NULL; /* Build the store */ /* Get Number of Columns */ res = xmlXPathEval((const xmlChar *)"/ProLinga/Repository/Command/Object/ListStore/NumColumns", ctxt); cols = (int)xmlXPathCastToNumber(res); /* Get Data Types from columns */ types = new GType[cols]; /* Process Column info */ res = xmlXPathEval((const xmlChar *)"count(/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader)", ctxt); insHits = (int)xmlXPathCastToNumber(res); /* Set number of columns */ newPtr->numCols = insHits; for (i = 1; i <= insHits; i++) { /* Get Column id */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnId", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); columnId = (int)xmlXPathCastToNumber(res); /* Get Column Label */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnLabel", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); /* Insert Column Header in memlist */ newPtr->putHeaderValue(&newPtr, name, columnId, (char *)xmlXPathCastToString(res)); /* Check if sort column */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/DefaultSort", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "True") == 0) { newPtr->sortCol = columnId; /* Check if sort column */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/SortDirection", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "None") == 0) newPtr->sortDirection = LIST_SORTING_NONE; else if (strcmp((char *)xmlXPathCastToString(res), "Descending") == 0) newPtr->sortDirection = LIST_SORTING_DESCENDING; else newPtr->sortDirection = LIST_SORTING_ASCENDING; } /* Get Column Type */ sprintf(stm, "/ProLinga/Repository/Command/Object/ListStore/OccurrencesListColumnHeader/ListColumnHeader[%d]/ColumnType", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); if (strcmp((char *)xmlXPathCastToString(res), "Text") == 0) { newPtr->putColumnDataType(&newPtr, name, columnId, LIST_TEXT); types[(i-1)] = G_TYPE_STRING; } else { newPtr->putColumnDataType(&newPtr, name, columnId, LIST_NUMBER); types[(i-1)] = G_TYPE_DOUBLE; } } /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storePtr = gtk_list_store_newv(cols, types); gtk_list_store_clear(storePtr); GTK_LIST_STORE(storePtr)->sort_column_id = -2; /* Process List Data */ /* Loop through all rows */ i = 1; for (;;) { sprintf(stm,"/ProLinga/Repository/Command/Object/ListStore/OccurrencesListData/ListData[RowId='%d']", i); res = xmlXPathEval((const xmlChar *)stm, ctxt); insHits = (int)res->nodesetval->nodeNr; if (insHits <= 0) break; /* Put in values */ gtk_list_store_append(storePtr, &iter); /* Get Column info */ for (j = 0; j < insHits; j++) { /* Get Column Id */ curRes = res->nodesetval->nodeTab[j]; for (curRes = curRes->xmlChildrenNode; curRes != NULL; curRes = curRes->next) { /* Column Id */ if (!xmlStrcmp(curRes->name, (const xmlChar *) "ColumnId")) { elementValue = xmlNodeListGetString(docRes, curRes->xmlChildrenNode, 1); columnId = atoi((char *)elementValue); xmlFree(elementValue); } /* Value */ else if (!xmlStrcmp(curRes->name, (const xmlChar *) "Value")) listValue = xmlNodeListGetString(docRes, curRes->xmlChildrenNode, 1); } /* Insert Value */ if (newPtr->getColumnDataType(newPtr, name, columnId) == LIST_TEXT) gtk_list_store_set(storePtr, &iter, (columnId - 1), (char *)listValue, -1); else { f = atof((char *)listValue); gtk_list_store_set(storePtr, &iter, (columnId - 1), f, -1); } /* Free */ xmlFree(listValue); } /* Raise Counter */ i++; } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Insert store */ newPtr->storePtr = storePtr; if (prevPtr == NULL) { /* First Record */ *listPtr = newPtr; } else { prevPtr->nextPtr = newPtr; } /* Clean up */ xmlFreeDoc(docRes); delete types; /* Return */ return newPtr->storePtr; } char *ListStore::getName(ListStore *listPtr, GtkListStore *store) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (store == curPtr->storePtr) return curPtr->listName; curPtr = curPtr->nextPtr; } /* Return */ return NULL; } int ListStore::getNumberRows(ListStore *listPtr, const char *name, const bool isMainThread) { ListStorePtr curPtr; int ret; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); ret = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(curPtr->storePtr), NULL); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Return */ return ret; } curPtr = curPtr->nextPtr; } /* Return */ return 0; } int ListStore::getNumberColumns(ListStore *listPtr, const char *name) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->numCols; curPtr = curPtr->nextPtr; } /* Return */ return 0; } void ListStore::putNumberColumns(ListStore *listPtr, const char *name, const int cols) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->numCols = cols; return; } curPtr = curPtr->nextPtr; } } int ListStore::getSortColumn(ListStore *listPtr, const char *name) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->sortCol; curPtr = curPtr->nextPtr; } /* Return */ return 0; } void ListStore::putSortColumn(ListStore *listPtr, const char *name, const int colNo) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->sortCol = colNo; return; } curPtr = curPtr->nextPtr; } } int ListStore::getSortDirection(ListStore *listPtr, const char *name) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->sortDirection; curPtr = curPtr->nextPtr; } /* Return */ return 0; } void ListStore::putSortDirection(ListStore *listPtr, const char *name, const int sorting) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->sortDirection = sorting; return; } curPtr = curPtr->nextPtr; } } void ListStore::addToList(ListStore **listPtr, const char *name, GtkListStore *storePtr) { ListStore *curPtr, *prevPtr, *newPtr, *tmpPtr; curPtr = *listPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { tmpPtr = curPtr; if (prevPtr == NULL) { *listPtr = curPtr->nextPtr; curPtr = *listPtr; } else { prevPtr->nextPtr = curPtr->nextPtr; curPtr = prevPtr; } delete tmpPtr; continue; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } newPtr = new ListStore; strcpy(newPtr->listName, name); newPtr->storePtr = storePtr; newPtr->nextPtr = NULL; if (prevPtr == NULL) *listPtr = newPtr; else prevPtr->nextPtr = newPtr; } void ListStore::updateStore(ListStore **listPtr, const char *name, GtkListStore *store, bool isMainThread) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { if (curPtr->storePtr != NULL) { /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); gtk_list_store_clear(curPtr->storePtr); g_object_unref (G_OBJECT (curPtr->storePtr)); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } curPtr->storePtr = store; return; } curPtr = curPtr->nextPtr; } } void ListStore::renameStore(ListStore **listPtr, const char *oldName, const char *newName) { ListStorePtr curPtr, prevPtr; /* Delete new name if exists */ curPtr = *listPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(newName, curPtr->listName) == 0) { if (prevPtr == NULL) *listPtr = curPtr->nextPtr; else prevPtr->nextPtr = curPtr->nextPtr; delete curPtr; break; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } /* Find old name */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(oldName, curPtr->listName) == 0) { strcpy(curPtr->listName, newName); break; } curPtr = curPtr->nextPtr; } } void ListStore::deleteFromList(ListStore **listPtr, const char *name) { ListStore *curPtr, *prevPtr; /* Empty List?*/ if (*listPtr == NULL) return; curPtr = *listPtr; prevPtr = NULL; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { /* Unlink variable */ if (prevPtr == NULL) *listPtr = curPtr->nextPtr; else prevPtr->nextPtr = curPtr->nextPtr; delete curPtr; break; } prevPtr = curPtr; curPtr = curPtr->nextPtr; } } void ListStore::deleteList(ListStore **listPtr) { ListStorePtr curPtr, tmpPtr; curPtr = *listPtr; *listPtr = NULL; while (curPtr != NULL) { tmpPtr = curPtr; curPtr = curPtr->nextPtr; delete tmpPtr; } } void ListStore::printList(ListStore *listPtr) const { ListStore *curPtr; curPtr = listPtr; while (curPtr != NULL) { printf("List Name : %s\n", curPtr->listName); curPtr = curPtr->nextPtr; } } /* Command : */ void CmdList(const char **argList, int argHits, bool isMainThread, bool idleEvent) { GtkListStore *store, *storeNew; GtkTreePath *path; GtkTreeIter iter, iterdest, iterNew; GtkTreeModel *model; GtkTreeSelection *selection; gchar *selValue, *position, *selString; GType *types; int i,j, cols=1, colNo, rowNo, num, offset; double f; gint numOfRows, numOfCols; gboolean valid; char storeName[32], value[255], string[255], retValue[255], *colLabel; const char *errorList[5]; /* Determine List Option */ if (strcmp(argList[1], "GETHEADER") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get Column No */ colNo = atoi(getDataRef(argList[4], isMainThread, retValue, false)); /* Process Arguments */ for (i = 5; i<= argHits; i=i+2) { /* Get column label */ if (strcmp(argList[i], "LABEL") == 0) { putDataRef(argList[i+1], listStorePtr->getHeaderValue(listStorePtr, storeName, colNo), 0, isMainThread); } /* Get column sort */ else if (strcmp(argList[i], "SORT") == 0) { if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) { if (listStorePtr->getSortDirection(listStorePtr, storeName) == LIST_SORTING_ASCENDING) putDataRef(argList[i+1], "Ascending", 0, isMainThread); else if (listStorePtr->getSortDirection(listStorePtr, storeName) == LIST_SORTING_DESCENDING) putDataRef(argList[i+1], "Descending", 0, isMainThread); else if (listStorePtr->getSortDirection(listStorePtr, storeName) == LIST_SORTING_NONE) putDataRef(argList[i+1], "None", 0, isMainThread); } else { putDataRef(argList[i+1], "None", 0, isMainThread); } } /* Get column type */ else if (strcmp(argList[i], "TYPE") == 0) { if (listStorePtr->getColumnDataType(listStorePtr, storeName, colNo) == LIST_NUMBER) putDataRef(argList[i+1], "Number", 0, isMainThread); else putDataRef(argList[i+1], "Text", 0, isMainThread); } } } else if (strcmp(argList[1], "PUTHEADER") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get Column No */ colNo = atoi(getDataRef(argList[4], isMainThread, retValue, false)); /* Process Arguments */ for (i = 5; i<= argHits; i=i+2) { /* Set column label */ if (strcmp(argList[i], "LABEL") == 0) { getDataRef(argList[i+1], isMainThread, retValue, false); listStorePtr->putHeaderValue(&listStorePtr, storeName, colNo, retValue); } /* Set column sorting */ else if (strcmp(argList[i], "SORT") == 0) { getDataRef(argList[i+1], isMainThread, retValue, false); if (strcmp(retValue, "Ascending") == 0) { listStorePtr->putSortColumn(listStorePtr, storeName, colNo); listStorePtr->putSortDirection(listStorePtr, storeName, LIST_SORTING_ASCENDING); } else if (strcmp(retValue, "Descending") == 0) { listStorePtr->putSortColumn(listStorePtr, storeName, colNo); listStorePtr->putSortDirection(listStorePtr, storeName, LIST_SORTING_DESCENDING); } else if (strcmp(retValue, "None") == 0) { /* Ignore column other than the current sort column */ if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) { listStorePtr->putSortColumn(listStorePtr, storeName, 0); listStorePtr->putSortDirection(listStorePtr, storeName, LIST_SORTING_NONE); GTK_LIST_STORE(store)->sort_column_id = -2; } } } /* Set column type */ else if (strcmp(argList[i], "TYPE") == 0) { getDataRef(argList[i+1], isMainThread, retValue, false); if (strcmp(retValue, "Number") == 0) listStorePtr->putColumnDataType(&listStorePtr, storeName, colNo, LIST_NUMBER); else listStorePtr->putColumnDataType(&listStorePtr, storeName, colNo, LIST_TEXT); } } } else if (strcmp(argList[1], "APPEND") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Append Row */ gtk_list_store_append (store, &iter); j = 0; for (i = 4; i <= argHits; i++) { getDataRefRaw(argList[i], isMainThread, value, false); if (listStorePtr->getColumnDataType(listStorePtr, storeName, (j+1)) == LIST_NUMBER) { f = atof(value); gtk_list_store_set (store, &iter, j, f, -1); } else { gtk_list_store_set (store, &iter, j, value, -1); } j++; } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[1], "GET") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get Column No */ colNo = atoi(getDataRef(argList[6], isMainThread, retValue, false)); /* Get Row No if given */ if (argHits > 7) { /* Get Row No */ rowNo = atoi(getDataRef(argList[8], isMainThread, retValue, false)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Set iter */ sprintf(string, "%d", (rowNo-1)); path = gtk_tree_path_new_from_string(string); gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (colNo-1), &selValue, -1); putDataRef(argList[4], selValue, 0, isMainThread); gtk_tree_path_free(path); g_free (selValue); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else { rowNo = 0; /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, (colNo-1), &selValue, -1); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } if (selValue == NULL) putDataRef(argList[4], "", 0, isMainThread); else putDataRef(argList[4], selValue, 0, isMainThread); g_free (selValue); } else printf("NO SELECTION \n"); } } else if (strcmp(argList[1], "INSERT") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get Column No */ colNo = atoi(getDataRef(argList[6], isMainThread, retValue, false)); /* Get value to set */ getDataRefRaw(argList[4], isMainThread, value, false); /* Get Row No if given */ if (argHits > 7) { /* Get Row No */ rowNo = atoi(getDataRef(argList[8], isMainThread, retValue, false)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Set iter */ sprintf(string, "%d", rowNo); path = gtk_tree_path_new_from_string(string); gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); gtk_list_store_set (store, &iter, (colNo-1), value, -1); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else { /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Get iter */ if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_list_store_set (store, &iter, (colNo-1), value, -1); } else printf("NO SELECTION \n"); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } } else if (strcmp(argList[1], "COLUMN") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get Column Action */ if (strcmp(argList[3], "APPEND") == 0) { /* Get number of columns to append */ if (argHits > 3) cols = atoi(getDataRef(argList[4], isMainThread, retValue, false)); else cols = 1; /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of new columns */ cols = cols + listStorePtr->getNumberColumns(listStorePtr, storeName); /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set all columns to default values */ for (i = 1; i <= cols; i++) { types[(i-1)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_TEXT); sprintf(string, "Col%d", i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", i, string); } /* Set values of existing columns */ for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", i, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_NUMBER); } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) <= cols) { listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); } else { listStorePtr->putSortColumn(listStorePtr, "_new_store_", 0); listStorePtr->putSortDirection(listStorePtr, "_new_store_", LIST_SORTING_NONE); } /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); gtk_list_store_set(storeNew, &iterNew, (i-1), selString, -1); //gtk_list_store_set(storeNew, &iterNew, (i-1), 123, -1); g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[3], "DELETE") == 0) { /* Get number of columns to delete */ if (argHits > 3) cols = atoi(getDataRef(argList[4], isMainThread, retValue, false)); else cols = 1; /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of new columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName) - cols; if (cols < 1) cols = 1; /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ for (i=1; i <= cols; i++) { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", i, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_NUMBER); } else { types[(i-1)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_TEXT); } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) <= cols) { listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); } else { listStorePtr->putSortColumn(listStorePtr, "_new_store_", 0); listStorePtr->putSortDirection(listStorePtr, "_new_store_", LIST_SORTING_NONE); } /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= cols; i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); gtk_list_store_set(storeNew, &iterNew, (i-1), selString, -1); //gtk_list_store_set(storeNew, &iterNew, (i-1), 123, -1); g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[3], "COPY") == 0) { /* Get number of column to copy */ if (argHits > 3) colNo = atoi(getDataRef(argList[4], isMainThread, retValue, false)); else colNo = listStorePtr->getNumberColumns(listStorePtr, storeName); /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of new columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName) + 1; /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", i, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_NUMBER); } else { types[(i-1)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", i, LIST_TEXT); } /* If reached column to be copied, copy data */ if (i == colNo) { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", cols, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(cols-1)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", cols, LIST_NUMBER); } else { types[(cols-1)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", cols, LIST_TEXT); } } } /* Set Sorting */ listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); gtk_list_store_set(storeNew, &iterNew, (i-1), selString, -1); /* If column to be copied, copy data */ if (i == colNo) gtk_list_store_set(storeNew, &iterNew, (cols-1), selString, -1); g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[3], "COLNO") == 0) { /* First, Left, Right, Last */ /* Get number of column to work on */ colNo = atoi(getDataRef(argList[4], isMainThread, retValue, false)); if (strcmp(argList[5], "FIRST") == 0) { /* If already first column, nothing to be done */ if (colNo == 1) return; /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of new columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName); /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ offset = 1; for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { if (i == colNo) { offset = 0; colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", 1, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[0] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", 1, LIST_NUMBER); } else { types[0] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", 1, LIST_TEXT); } } else { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i+offset), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1+offset)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+offset), LIST_NUMBER); } else { types[(i-1+offset)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+offset), LIST_TEXT); } } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) listStorePtr->putSortColumn(listStorePtr, "_new_store_", 1); else if (listStorePtr->getSortColumn(listStorePtr, storeName) == 1) listStorePtr->putSortColumn(listStorePtr, "_new_store_", 2); else listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { offset = 1; gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); /* If column to be copied, copy data */ if (i == colNo) { offset = 0; gtk_list_store_set(storeNew, &iterNew, 0, selString, -1); } else gtk_list_store_set(storeNew, &iterNew, (i-1+offset), selString, -1); g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[5], "LAST") == 0) { /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName); /* If already last column, nothing to be done */ if (colNo == cols) return; /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ offset = 0; for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { if (i == colNo) { offset = 1; colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", cols, colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(cols-1)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", cols, LIST_NUMBER); } else { types[(cols-1)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", cols, LIST_TEXT); } } else { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i-offset), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1-offset)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_NUMBER); } else { types[(i-1-offset)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_TEXT); } } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) listStorePtr->putSortColumn(listStorePtr, "_new_store_", cols); else if (listStorePtr->getSortColumn(listStorePtr, storeName) == cols) listStorePtr->putSortColumn(listStorePtr, "_new_store_", (cols-1)); else listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { offset = 0; gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); /* If column to be copied, copy data */ if (i == colNo) { offset = 1; gtk_list_store_set(storeNew, &iterNew, (cols-1), selString, -1); } else gtk_list_store_set(storeNew, &iterNew, (i-1-offset), selString, -1); g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[5], "LEFT") == 0) { /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName); /* If first column, no action */ if (cols == 1) return; /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ offset = 0; for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { if (i == (colNo-1)) { offset = 1; colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i+1), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[i] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+1), LIST_NUMBER); } else { types[i] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+1), LIST_TEXT); } } else { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i-offset), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1-offset)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_NUMBER); } else { types[(i-1-offset)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_TEXT); } offset = 0; } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) listStorePtr->putSortColumn(listStorePtr, "_new_store_", (colNo-1)); else if (listStorePtr->getSortColumn(listStorePtr, storeName) == (colNo-1)) listStorePtr->putSortColumn(listStorePtr, "_new_store_", colNo); else listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { offset = 0; gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); /* If column to be copied, copy data */ if (i == (colNo-1)) { offset = 1; gtk_list_store_set(storeNew, &iterNew, (i), selString, -1); } else { gtk_list_store_set(storeNew, &iterNew, (i-1-offset), selString, -1); offset = 0; } g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } else if (strcmp(argList[5], "RIGHT") == 0) { /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get total of columns */ cols = listStorePtr->getNumberColumns(listStorePtr, storeName); /* If last column, no action */ if (cols == colNo) return; /* Create entry for new store */ storeNew = NULL; listStorePtr->addToList(&listStorePtr, "_new_store_", storeNew); /* Set number of columns */ listStorePtr->putNumberColumns(listStorePtr, "_new_store_", cols); /* Get Data Types from columns */ types = new GType[cols]; /* Set values of existing columns */ offset = 0; for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { if (i == colNo) { offset = 1; colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i+1), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[i] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+1), LIST_NUMBER); } else { types[i] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i+1), LIST_TEXT); } } else { colLabel = listStorePtr->getHeaderValue(listStorePtr, storeName, i); listStorePtr->putHeaderValue(&listStorePtr, "_new_store_", (i-offset), colLabel); if (listStorePtr->getColumnDataType(listStorePtr, storeName, i) == LIST_NUMBER) { types[(i-1-offset)] = G_TYPE_DOUBLE; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_NUMBER); } else { types[(i-1-offset)] = G_TYPE_STRING; listStorePtr->putColumnDataType(&listStorePtr, "_new_store_", (i-offset), LIST_TEXT); } offset = 0; } } /* Set Sorting */ if (listStorePtr->getSortColumn(listStorePtr, storeName) == colNo) listStorePtr->putSortColumn(listStorePtr, "_new_store_", (colNo+1)); else if (listStorePtr->getSortColumn(listStorePtr, storeName) == (colNo+1)) listStorePtr->putSortColumn(listStorePtr, "_new_store_", colNo); else listStorePtr->putSortColumn(listStorePtr, "_new_store_", listStorePtr->getSortColumn(listStorePtr, storeName)); listStorePtr->putSortDirection(listStorePtr, "_new_store_", listStorePtr->getSortDirection(listStorePtr, storeName)); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Create Store */ storeNew = gtk_list_store_newv(cols, types); gtk_list_store_clear(storeNew); GTK_LIST_STORE(storeNew)->sort_column_id = -2; /* Copy Data */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); while (valid) { offset = 0; gtk_list_store_append (storeNew, &iterNew); for (i=1; i <= listStorePtr->getNumberColumns(listStorePtr, storeName); i++) { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, (i-1), &selString, -1); /* If column to be copied, copy data */ if (i == colNo) { offset = 1; gtk_list_store_set(storeNew, &iterNew, (i), selString, -1); } else { gtk_list_store_set(storeNew, &iterNew, (i-1-offset), selString, -1); offset = 0; } g_free(selString); } valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } /* Rename new store to store */ listStorePtr->updateStore(&listStorePtr, "_new_store_", storeNew, isMainThread); listStorePtr->renameStore(&listStorePtr, "_new_store_", storeName); } } } else if (strcmp(argList[1], "ROW") == 0) { /* Get Store Name */ getDataRef(argList[2], isMainThread, storeName, false); /* Get store pointer */ store = listStorePtr->getStore(&listStorePtr, storeName, isMainThread); /* Get Column Action */ if (strcmp(argList[3], "TOP") == 0) { /* If list has a sort column, ignore */ if (listStorePtr->getSortColumn(listStorePtr, storeName) != 0) { errorList[1] = "Can not move row with active sort column"; CmdError(errorList, 1, isMainThread, NULL, idleEvent); return; } /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Swap rows */ gtk_list_store_prepend(store, &iterdest); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_list_store_swap(store, &iter, &iterdest); gtk_list_store_remove (store, &iterdest); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[3], "BOTTOM") == 0) { /* If list has a sort column, ignore */ if (listStorePtr->getSortColumn(listStorePtr, storeName) != 0) { errorList[1] = "Can not move row with active sort column"; CmdError(errorList, 1, isMainThread, NULL, idleEvent); return; } /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Swap rows */ gtk_list_store_append(store, &iterdest); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_list_store_swap(store, &iter, &iterdest); gtk_list_store_remove (store, &iterdest); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[3], "UP") == 0) { /* If list has a sort column, ignore */ if (listStorePtr->getSortColumn(listStorePtr, storeName) != 0) { errorList[1] = "Can not move row with active sort column"; CmdError(errorList, 1, isMainThread, NULL, idleEvent); return; } /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Move rows */ if (gtk_tree_selection_get_selected (selection, &model, &iter)) { position = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(store), &iter); num = atoi(position); num = num - 1; if (num >= 0) { sprintf(string, "%d", num); path = gtk_tree_path_new_from_string(string); gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iterdest, path); gtk_tree_path_free(path); gtk_list_store_swap(store, &iter, &iterdest); } } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[3], "DOWN") == 0) { /* If list has a sort column, ignore */ if (listStorePtr->getSortColumn(listStorePtr, storeName) != 0) { errorList[1] = "Can not move row with active sort column"; CmdError(errorList, 1, isMainThread, NULL, idleEvent); return; } /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Move rows */ if (gtk_tree_selection_get_selected (selection, &model, &iter)) { numOfRows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); position = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(store), &iter); num = atoi(position); num = num + 1; if (num < numOfRows) { sprintf(string, "%d", num); path = gtk_tree_path_new_from_string(string); gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iterdest, path); gtk_tree_path_free(path); gtk_list_store_swap(store, &iter, &iterdest); } } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[3], "COPY") == 0) { /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { /* Get number of columns */ numOfCols = gtk_tree_model_get_n_columns(model); /* Set Iter */ gtk_list_store_insert_after(store, &iterdest, &iter); /* Copy fields */ for (colNo = 0; colNo < numOfCols; colNo++) { gtk_tree_model_get (model, &iter, colNo, &selValue, -1); gtk_list_store_set (store, &iterdest, colNo, selValue, -1); g_free (selValue); } } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[3], "DELETE") == 0) { /* Get Selection */ selection = listStorePtr->getSelection(listStorePtr, storeName); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); if (gtk_tree_selection_get_selected (selection, &model, &iter)) gtk_list_store_remove (store, &iter); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } } else printf("Invalid List Option : %s\n", argList[1]); /* Return */ return; } char *ListStore::getHeaderValue(ListStore *listPtr, const char *name, const int colNo) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->startPtr->getValue(curPtr->startPtr, colNo); curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void ListStore::putHeaderValue(ListStore **listPtr, const char *name, const int colNo, const char *labelText) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->startPtr->putValue(&curPtr->startPtr, colNo, labelText); return; } curPtr = curPtr->nextPtr; } } int ListStore::getColumnDataType(ListStore *listPtr, const char *name, const int colNo) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->startPtr->getDataType(curPtr->startPtr, colNo); curPtr = curPtr->nextPtr; } /* Return */ return 1; } void ListStore::putColumnDataType(ListStore **listPtr, const char *name, const int colNo, const int type) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->startPtr->putDataType(&curPtr->startPtr, colNo, type); return; } curPtr = curPtr->nextPtr; } } GtkTreeSelection *ListStore::getSelection(ListStore *listPtr, const char *name) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) return curPtr->cbSelection; curPtr = curPtr->nextPtr; } /* Return */ return NULL; } void ListStore::putSelection(ListStore **listPtr, const char *name, GtkTreeSelection *selection) { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = *listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->cbSelection = selection; return; } curPtr = curPtr->nextPtr; } } void ListStore::printHeaderList(ListStore *listPtr, const char *name) const { ListStorePtr curPtr; /* Check if store exists in memory */ curPtr = listPtr; while (curPtr != NULL) { if (strcmp(name, curPtr->listName) == 0) { curPtr->startPtr->printList(curPtr->startPtr); return; } curPtr = curPtr->nextPtr; } } void ListStore::printStoreList(ListStore *listPtr) const { ListStorePtr curPtr; curPtr = listPtr; while (curPtr != NULL) { printf("List Store Name %s\n", curPtr->listName); printf("List Store No Cols %d\n", curPtr->numCols); printf("List Store Sort Col %d\n", curPtr->sortCol); printf("List Store Sort Direction %d\n", curPtr->sortDirection); curPtr = curPtr->nextPtr; } }