bool ScreenSetup::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event)) return true; bool handled = false; QStringList actions; handled = GetMythMainWindow()->TranslateKeyPress("Weather", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (action == "DELETE") { if (GetFocusWidget() == m_activeList) deleteScreen(); } else handled = false; } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
void ScreenSetup::customEvent(QEvent *event) { if (event->type() == DialogCompletionEvent::kEventType) { DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); QString resultid = dce->GetId(); int buttonnum = dce->GetResult(); if (resultid == "options") { if (buttonnum > -1) { MythUIButtonListItem *item = dce->GetData().value<MythUIButtonListItem *>(); ScreenListInfo *si = item->GetData().value<ScreenListInfo *>(); if (buttonnum == 0) { m_activeList->MoveItemUpDown(item, true); } else if (buttonnum == 1) { m_activeList->MoveItemUpDown(item, false); } else if (buttonnum == 2) { deleteScreen(); } else if (buttonnum == 3) { si->updating = true; doLocationDialog(si); } else if (si->hasUnits && buttonnum == 4) { si->updating = true; showUnitsPopup(item->GetText(), si); updateHelpText(); } } } else if (resultid == "units") { if (buttonnum > -1) { ScreenListInfo *si = dce->GetData().value<ScreenListInfo *>(); if (buttonnum == 0) { si->units = ENG_UNITS; } else if (buttonnum == 1) { si->units = SI_UNITS; } updateHelpText(); if (si->updating) si->updating = false; else doLocationDialog(si); } } else if (resultid == "location") { ScreenListInfo *si = dce->GetData().value<ScreenListInfo *>(); TypeListMap::iterator it = si->types.begin(); for (; it != si->types.end(); ++it) { if ((*it).location.isEmpty()) return; } if (si->updating) { si->updating = false; MythUIButtonListItem *item = m_activeList->GetItemCurrent(); if (item) item->SetData(qVariantFromValue(si)); } else { QString txt = si->title; txt.detach(); MythUIButtonListItem *item = new MythUIButtonListItem(m_activeList, txt); item->SetData(qVariantFromValue(si)); } if (m_activeList->GetCount()) m_activeList->SetEnabled(true); } } }
//Huge main function. int main(int argc, char *argv[]) { if (argc < 3){ //if you don't type enough arguments printf("Sockets client, usage:\n"); printf("sockets_client {IP-address} {port} \n"); return 0; } else { free(server); server = malloc((strlen(argv[1] + 1) * sizeof(char))); strcpy(server, argv[1]); portno = atoi(argv[2]); } int c; while(1){ if(screen == 0){ CATEGORY = 8; currentRecord = 0; recordView = 0; xt_par0(XT_CLEAR_SCREEN); lifeTracker(); xt_par2(XT_SET_ROW_COL_POS,row = 8, col = 2); } while(screen == 0) { while((c = getkey()) == KEY_NOTHING); if(c == KEY_F9) screen = 3; else if(c == KEY_F3 && maxRecord > 0 && col == 20) screen = 4; else if(c == KEY_DOWN) { if(col == 2 && row >= 8 && row < catCounter + 7){ xt_par2(XT_SET_ROW_COL_POS,CATEGORY = ++row,col); updateRecords(recordView); } if(col == 20 && row >= 7 && row <= tempCounter * 5 + 1){ if(row < 22){ xt_par2(XT_SET_ROW_COL_POS,row+=5,col); ++currentRecord; } else if(recordView < tempCounter-4){ ++recordView; if(search == 1) searchResults(recordView); else updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=22,col); ++currentRecord; } } if(col > 94 && col < 120){ if(row == 9) xt_par2(XT_SET_ROW_COL_POS,row = 12,col = 95); else if(row == 12) xt_par2(XT_SET_ROW_COL_POS,row = 13,col = 95); else if(row == 13) xt_par2(XT_SET_ROW_COL_POS,row = 16,col); else if(row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col); else if(row == 20 && col < 110) xt_par2(XT_SET_ROW_COL_POS,++row,col); else if(row == 20 && col > 110) xt_par2(XT_SET_ROW_COL_POS,++row,col = 109); } } else if(c == KEY_UP){ if(col == 2 && row > 8 && row <= 18){ xt_par2(XT_SET_ROW_COL_POS,CATEGORY = --row,col); updateRecords(recordView); } if(col == 20 && row >= 7 && row < 24){ if(row <= 24 && row > 7){ xt_par2(XT_SET_ROW_COL_POS,row-=5,col); --currentRecord; } else if(recordView > 0){ --recordView; if(search == 1) searchResults(recordView); else updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=7,col); --currentRecord; } } if(row > 9 && col > 94 && col < 120){ if(row == 12) xt_par2(XT_SET_ROW_COL_POS,row = 9,col = 95); else if(row == 13) xt_par2(XT_SET_ROW_COL_POS,row = 12,col = 95); else if(row == 16) xt_par2(XT_SET_ROW_COL_POS, row = 13, col = 95); else if(row < 22) xt_par2(XT_SET_ROW_COL_POS, --row, col); } } else if(c == KEY_ENTER && col > 94 && col < 120 && row > 12 && row < 18) xt_par2(XT_SET_ROW_COL_POS,++row,col=95); else if((c == KEY_LEFT || c == KEY_RIGHT) && col == 2) { CATEGORY = row; updateRecords(recordView); xt_par2(XT_SET_ROW_COL_POS,row=7,col=20); } else if((c == KEY_LEFT || c == KEY_RIGHT) && col == 20) { xt_par2(XT_SET_ROW_COL_POS,row=CATEGORY,col=2); if (search == 1) clearSearch(); currentRecord = recordView = search = 0; updateRecords(recordView); } else if(c == KEY_LEFT && col >= 95) { if(col > 95) xt_par2(XT_SET_ROW_COL_POS,row,--col); else if(row == 13 && col == 95) xt_par2(XT_SET_ROW_COL_POS,--row,col = 101); else if(row >= 17 && row <= 21 && col == 95) xt_par2(XT_SET_ROW_COL_POS,--row, col = 119); } else if(c == KEY_RIGHT && col > 94) { if(row == 9 && col < 112) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 12 && col < 101) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 12 && col == 101) xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); else if(row == 13 && col < 112) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row >= 16 && row < 21 && col < 119) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row == 21 && col < 109) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(row >= 16 && row <= 21 && col == 119) xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); } else if(c == KEY_DELETE) { putchar(' '); if(row == 9) Category[col - 95] = ' '; else if(row == 12) Title[col - 95] = ' '; else if(row == 13) Title[col - 88] = ' '; else if(row >= 16 && row < 22) Body[(row - 16) * 25 + col - 95] = ' '; } else if(c == KEY_BACKSPACE && col >= 95) { if((row == 9 || row == 12) && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Category[col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if((row == 9 || row == 12) && col == 95) { putchar(' '); Title[col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 13 && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Title[col - 88] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 13 && col == 95) { xt_par2(XT_SET_ROW_COL_POS,--row,col = 101); putchar(' '); Title[col - 88] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row >= 16 && row < 22 && col > 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 16 && col == 95) { putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row > 16 && row < 22 && col == 95) { xt_par2(XT_SET_ROW_COL_POS,--row,col = 119); putchar(' '); Body[(row - 16) * 25 + col - 95] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if((c >= ' ' && c <= '~') && col >= 95 && col < 120){ if(row == 9 && col < 112) { putchar(c); Category[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 9 && col == 112) { putchar(c); Category[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row == 12 && col < 101) { putchar(c); Title[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 12 && col == 101) { putchar(c); Title[col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,++row,col=95); } else if(row == 13 && col < 112) { putchar(c); Title[col - 88] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 13 && col == 112) { putchar(c); Title[col - 88] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if(row >= 16 && row < 21 && col < 119) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row >= 16 && row < 21 && col == 119) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,++row,col = 95); } else if(row == 21 && col < 109) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,++col); } else if(row == 21 && col == 109) { putchar(c); Body[(row - 16) * 25 + col - 95] = c; xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if(c == KEY_F2) screen = 1; else if(c == KEY_F4 && col == 20 && maxRecord != 0) screen = 2; else if(c == KEY_F6) { if(sort == 0){ bubbleSort(); sort = 1; } else if (sort == 1){ bubbleSortTime(); sort = 0; } } else if (c == KEY_F7){ if(col < 95) { xt_par2(XT_SET_ROW_COL_POS,row = 9,col = 95); for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; } else if(Title[0] == ' ' && Body[0] == ' ' && Category[0] == ' ') { xt_par2(XT_SET_ROW_COL_POS,row = CATEGORY,col = 2); clearSearch(); updateRecords(0); } else if(Title[0] != ' ' || Body[0] != ' ' || Category[0] != ' ') { clearSearch(); search = 1; searchResults(0); xt_par2(XT_SET_ROW_COL_POS,row = 7, col = 20); } } } if (screen == 1 || screen == 2){ for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; addScreen(); if (screen == 2){ char TempBodyA[71]; char TempBodyB[71]; int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } k = 0; xt_par2(XT_SET_ROW_COL_POS, row = 12, col = 25); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", currentRecord+1, catStorage[currentRecord].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); printf("%s", catStorage[currentRecord].category); int j = 0; while(catStorage[currentRecord].body[j] != '\0'){ if (j < 70) TempBodyA[j] = catStorage[currentRecord].body[j]; else if (j < 140) TempBodyB[j%70] = catStorage[currentRecord].body[j]; j++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); printf("%s", catStorage[currentRecord].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 19, col = 25); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, row = 20, col = 25); printf("%s", TempBodyB); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); strncpy(Title, catStorage[currentRecord].subject, sizeof(Title)); strncpy(Body, catStorage[currentRecord].body, sizeof(Body)); strncpy(Category, catStorage[currentRecord].category, sizeof(Category)); } } while(screen == 1 || screen == 2) { while((c = getkey()) == KEY_NOTHING); if (c == KEY_F9){ screen = 0; xt_par0(XT_CLEAR_SCREEN); } else if (c == KEY_DOWN){ if(row == 14) xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); else if(row == 16) xt_par2(XT_SET_ROW_COL_POS,row = 19,col = 25); else if(row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col); } else if (c == KEY_UP){ if(row == 16) xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); if(row == 19) xt_par2(XT_SET_ROW_COL_POS,row = 16,col = 25); else if(row == 20) xt_par2(XT_SET_ROW_COL_POS,--row,col); } else if(c == KEY_LEFT && col > 25 && col < 95) xt_par2(XT_SET_ROW_COL_POS,row,--col); else if(c == KEY_LEFT && col == 25 && row == 20) xt_par2(XT_SET_ROW_COL_POS,--row,col=94); else if(c == KEY_RIGHT && col > 24 && col < 37 && row == 14) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col > 24 && col < 53 && row == 16) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col > 24 && col < 94 && row > 18) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if(c == KEY_RIGHT && col == 94 && row == 19) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else if (c == KEY_ENTER && row > 18 && row < 20) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else if (c == KEY_BACKSPACE && col >= 25 && col < 95 && ((row > 18 && row < 21) || row == 16 || row == 14)){ if(row == 14 && col > 25 && col < 39) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Category[col - 25] = ' '; } else if(row == 16 && col > 25 && col <= 54) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Title[col - 25] = ' '; } else if(row == 19 && col > 25 && col <= 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[col - 25] = ' '; } else if(row == 20 && col > 25 && col <= 95) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Body[col + 45] = ' '; } else if(row == 20){ xt_par2(XT_SET_ROW_COL_POS,--row,col=94); putchar(' '); Body[69] = ' '; } xt_par2(XT_SET_ROW_COL_POS,row,col); } else if (c == KEY_DELETE) { if(row == 14 && col >= 25 && col < 38) { putchar(' '); Category[col - 25] = ' '; } else if(row == 16 && col >= 25 && col < 54) { putchar(' '); Title[col - 25] = ' '; } else if(row == 19 && col >= 25 && col <= 95) { putchar(' '); Body[col - 25] = ' '; } else if(row == 20 && col >= 25 && col <= 95) { putchar(' '); Body[col + 45] = ' '; } xt_par2(XT_SET_ROW_COL_POS,row,col); } else if((c >= ' ' && c <= '~') && col >= 25 && col < 95) { if(row == 14 && col >= 25 && col < 40) { putchar(c); Category[col - 25] = c; } else if(row == 16 && col >= 25 && col < 54) { putchar(c); Title[col - 25] = c; } else if(row == 19 && col >= 25 && col <= 95) { putchar(c); Body[col - 25] = c; } else if(row == 20 && col >= 25 && col <= 95) { putchar(c); Body[col + 45] = c; } if (col < 94 && !(row == 16 && col > 52) && !(row == 14 && col > 36)){ ++col; } else{ if (row == 19) xt_par2(XT_SET_ROW_COL_POS,++row,col=25); else xt_par2(XT_SET_ROW_COL_POS,row,col); } } else if(c == KEY_F2 && screen == 1 /* && there is a valid title and description */){ //save record to corresponding subject if(Title[0] != ' ' || Body[0] != ' ' || Category[0] != ' ') { removeBlanks(); readmyStoreFromChildSOCKETS("add", Title, Body, Category, NULL); } int k = 0; while(k != 29) Title[k++] = ' '; k = 0; while(k != 140) Body[k++] = ' '; k = 0; while(k != 15) Category[k++] = ' '; maxRecord++; screen = 0; } else if(c == KEY_F2 && screen == 2 /* && there has been a valid change in the record */){ //update record removeBlanks(); char str[80]; for(i = 0; i < maxRecord; i++){ if(strcmp(catStorage[currentRecord].subject, dataStorage[i].subject) == 0 && strcmp(catStorage[currentRecord].body, dataStorage[i].body) == 0 && strcmp(catStorage[currentRecord].category, dataStorage[i].category) == 0 && strcmp(catStorage[currentRecord].timedate, dataStorage[i].timedate) == 0){//looks for corresponding record in the actual record list sprintf(str, "%d", i+1); break; } } readmyStoreFromChildSOCKETS("edit", str, Title, Body, Category); int k = 0; while(k != 29) Title[k++] = ' '; k = 0; while(k != 140) Body[k++] = ' '; k = 0; while(k != 15) Category[k++] = ' '; screen = 0; } } if (screen == 4){ for(reset = 0; reset < 29; reset++) Title[reset] = ' '; for(reset = 0; reset < 140; reset++) Body[reset] = ' '; for(reset = 0; reset < 16; reset++) Category[reset] = ' '; deleteScreen(); if (screen == 4){ char TempBodyA[71]; char TempBodyB[71]; int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } k = 0; xt_par2(XT_SET_ROW_COL_POS, row = 12, col = 25); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", currentRecord+1, catStorage[currentRecord].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); printf("%s", catStorage[currentRecord].category); int j = 0; while(catStorage[currentRecord].body[j] != '\0'){ if (j < 70) TempBodyA[j] = catStorage[currentRecord].body[j]; else if (j < 140) TempBodyB[j%70] = catStorage[currentRecord].body[j]; j++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; xt_par2(XT_SET_ROW_COL_POS, row = 16, col = 25); printf("%s", catStorage[currentRecord].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 19, col = 25); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, row = 20, col = 25); printf("%s", TempBodyB); xt_par2(XT_SET_ROW_COL_POS, row = 14, col = 25); strncpy(Title, catStorage[currentRecord].subject, sizeof(Title)); strncpy(Body, catStorage[currentRecord].body, sizeof(Body)); strncpy(Category, catStorage[currentRecord].category, sizeof(Category)); //print corresponding record in correct locations using myui1 } } while(screen == 4) { while((c = getkey()) == KEY_NOTHING); if (c == KEY_F9){ screen = 0; xt_par0(XT_CLEAR_SCREEN); } else if (c == KEY_F3){ char str[80]; for(i = 0; i < maxRecord; i++){ if(strcmp(catStorage[currentRecord].subject, dataStorage[i].subject) == 0 && strcmp(catStorage[currentRecord].body, dataStorage[i].body) == 0 && strcmp(catStorage[currentRecord].category, dataStorage[i].category) == 0 && strcmp(catStorage[currentRecord].timedate, dataStorage[i].timedate) == 0){ //looks for corresponding record in the actual record list sprintf(str, "%d", i+1); break; } } readmyStoreFromChildSOCKETS("delete", str, NULL, NULL, NULL); maxRecord--; screen = 0; } } if (screen == 3) break; } getkey_terminate(); xt_par0(XT_CLEAR_SCREEN); xt_par0(XT_BG_DEFAULT); xt_par2(XT_SET_ROW_COL_POS,row=1,col=1); getkey_terminate(); return 0; }