bool Workspace::saveOnQuit() { for(int i = 0; i < mSheetList.size(); i++) { if ( mSheetList.at(i)->fileName().isEmpty() ) { int res = KMessageBox::warningYesNoCancel( this, i18n( "The tab '%1' contains unsaved data.\n" "Do you want to save the tab?", tabText(indexOf( mSheetList.at(i) )) ), QString(), KStandardGuiItem::save(), KStandardGuiItem::discard() ); if ( res == KMessageBox::Yes ) saveWorkSheet( mSheetList.at(i) ); else if ( res == KMessageBox::Cancel ) return false; // abort quit } else saveWorkSheet(mSheetList.at(i)); } return true; }
void Workspace::removeAllWorkSheets() { WorkSheet *sheet; while ( ( sheet = (WorkSheet*)currentWidget() ) != 0 ) { saveWorkSheet( sheet ); removeTab(indexOf( sheet )); mSheetList.removeAll( sheet ); delete sheet; } }
void Workspace::removeWorkSheet() { WorkSheet *current = (WorkSheet*)currentWidget(); if ( current ) { saveWorkSheet( current ); removeTab(indexOf( current )); mSheetList.removeAll( current ); } else { QString msg = i18n( "There are no tabs that could be deleted." ); KMessageBox::error( this, msg ); } }
/** * Initiates loop to run spreadsheet program until user quits * @param response Pointer to store the value entered by user at command prompt * @param spreadsheet The spreadsheet of cells * @param value Pointer that stores the value to be entered into a cell within the spreadsheet * @param address Pointer that stores the address of cell to store value * @param formula Pointer that stores formula * @param fType Pointer that stores the FormulaType to perform calculations */ void run(char *response, Cell spreadsheet[], char *value, size_t *address, char *formula, FormulaType *fType, int socket) { size_t addr; char val[IN_BUF_LIMIT]; char cacheAddr[CELL_ADDRESS]; char formatStr[80]; if (!recoveredSpreadSheet) initSpreadSheet(spreadsheet); displaySpreadSheetToClient(spreadsheet, socket); while (true) { if (!prompt(response, value, socket)) break; // cell guaranteed to be valid, no need for if statement. findCell(spreadsheet, response, address); addr = *address; printf("Address is: %lu\n", addr); printf("Value has %lu chars and is %s\n", strlen(value), value); sprintf(formatStr, "Old value: %s. New value: %s.\n", spreadsheet[addr].value, value); // fflush(st) printf("%s\n", value); // SOCKET_WRITE(socket, formatStr, MSG_DONTWAIT); SOCKET_WRITE(socket, "Return to reload spreadsheet", 0); if (isFormula(value, formula, fType)) { strcpy(cacheAddr, response); spreadsheet[addr].type = FORMULA; puts("FORMULA"); sprintf(val, "%f", calculateFormula(value, fType, spreadsheet, address)); printf("Val is %s\n", val); strcpy(spreadsheet[addr].value, val); spreadsheet[addr].address[0] = cacheAddr[0]; spreadsheet[addr].address[1] = cacheAddr[1]; spreadsheet[addr].address[2] = '\0'; } else if (cellAlNum(value) == true) { spreadsheet[addr].type = ALNUM; puts("ALNUM"); strcpy(spreadsheet[addr].value, value); } else { spreadsheet[addr].type = NUM; puts("NUM"); strcpy(spreadsheet[addr].value, value); // SEG-FAULTS HERE! } displaySpreadSheetToClient(spreadsheet, socket); saveWorkSheet(spreadsheet, socket); } SOCKET_WRITE(socket, "U got served bitch!", MSG_DONTWAIT); }