static void default_callback(newtComponent co __attribute__ ((unused)), void * data) { newtComponent * entries = (newtComponent *)data; char * strings[50], ** ptr; if (!callback_real_function) return; ptr = strings; while (entries && *entries) { *ptr = newtEntryGetValue(*entries); entries++; ptr++; } callback_real_function(strings); ptr = strings; entries = (newtComponent *)data; while (entries && *entries) { newtEntrySet(*entries, strdup(*ptr), 1); entries++; ptr++; } }
static void nmt_newt_entry_set_text_internal (NmtNewtEntry *entry, const char *text, newtComponent co) { NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry); if (!text) text = ""; if (!strcmp (priv->text, text)) return; g_free (priv->text); priv->text = g_strdup (text); if (co) { char *text_lc; text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL; newtEntrySet (co, text_lc, TRUE); g_free (text_lc); priv->last_cursor_pos = -1; } g_object_freeze_notify (G_OBJECT (entry)); nmt_newt_entry_check_valid (entry); g_object_notify (G_OBJECT (entry), "text"); g_object_thaw_notify (G_OBJECT (entry)); }
static char *newKickstartLocation(const char *origLocation) { const char *location; char *retval = NULL; newtComponent f, okay, cancel, answer, locationEntry; newtGrid grid, buttons; startNewt(); locationEntry = newtEntry(-1, -1, NULL, 60, &location, NEWT_FLAG_SCROLL); newtEntrySet(locationEntry, origLocation, 1); /* button bar at the bottom of the window */ buttons = newtButtonBar(_("OK"), &okay, _("Cancel"), &cancel, NULL); grid = newtCreateGrid(1, 3); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, newtTextboxReflowed(-1, -1, _("Unable to download the kickstart file. Please modify the kickstart parameter below or press Cancel to proceed as an interactive installation."), 60, 0, 0, 0), 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, locationEntry, 0, 1, 0, 0, NEWT_ANCHOR_LEFT, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); f = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, f, 1); newtGridWrappedWindow(grid, _("Error downloading kickstart file")); newtGridFree(grid, 1); /* run the form */ answer = newtRunForm(f); if (answer != cancel) retval = strdup(location); newtFormDestroy(f); newtPopWindow(); return retval; }
// return a malloc()ed path char *filesel(char *dr) { newtComponent lb, b1, b2, b3, l1, l2, f; const char *enr2, *enr3; char *curv; char curvv[PATH_MAX]; // stupid, but who cares... int i, cnt; fde *sel, *sela; char cwd[PATH_MAX], cwdcd[PATH_MAX], *ret=NULL; struct newtExitStruct es; struct stat st; newtCenteredWindow(65, 15, i18n("Select path")); f = newtForm(NULL, NULL, 0); b1 = newtCompactButton(59, 14, i18n("Ok")); b3 = newtCompactButton(45, 14, i18n("Cancel")); l2 = newtEntry(1, 14, "", 25, &enr3, NEWT_FLAG_SCROLL); b2 = newtCompactButton(26, 14, i18n("Create dir")); lb = newtListbox(1, 2, 12, /*NEWT_FLAG_MULTIPLE |*/ /*NEWT_FLAG_BORDER | */ NEWT_FLAG_RETURNEXIT | NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR); if(dr && strlen(dr) > 0) { // let it show the file or dir at any case l1 = newtEntry(1, 0, dr, 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED); stat(dr,&st); if(S_ISDIR(st.st_mode)) { dir_here(lb,dr); strcpy(cwd,dr); } else { dir_here(lb,dirname(dr)); strcpy(cwd,dirname(dr)); } } else { // if NULL, show the current dir l1 = newtEntry(1, 0, get_current_dir_name(), 60, &enr2, NEWT_FLAG_SCROLL | NEWT_FLAG_DISABLED); dir_here(lb,get_current_dir_name()); strcpy(cwd,get_current_dir_name()); } newtListboxSetWidth(lb,63); newtFormAddComponents(f, lb,l1, l2, b2, b1, b3, NULL); newtRefresh(); newtFormSetTimer(f, 200); do { newtFormRun(f, &es); if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == lb) { sel=(fde*)newtListboxGetCurrent(lb); if (sel && S_ISDIR(sel->st.st_mode)) { cnt=newtListboxItemCount(lb); // delete items there: for(i=0; i < cnt; i++) { newtListboxGetEntry(lb, i, &curv, (void**)&sela); if(sela != sel) { free(sela->name); free(sela); } else { strcpy(curvv, curv); } } newtListboxClear(lb); dir_here(lb,sel->name); if(strcmp(curvv,"..") == 0) set_lb_cursor(lb,cwdcd); strcpy(cwd,sel->name); strcpy(cwdcd,sel->name); newtEntrySet(l1, sel->name, 1); if(sel) { free(sel->name); free(sel); } } if(sel && S_ISREG(sel->st.st_mode)) // is a directory { newtEntrySet(l1, sel->name, 1); } } else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b2) { if(strlen(enr3) > 0) { strcpy(cwdcd,cwd); strcat(cwdcd,"/"); strcat(cwdcd,enr3); if(mkdir(cwdcd,0755) == 0) { newtListboxClear(lb); dir_here(lb,cwd); set_lb_cursor(lb,cwdcd); newtEntrySet(l2, "", 1); } } } else if (es.reason == es.NEWT_EXIT_COMPONENT && es.u.co == b1) { ret=strdup(enr2); } } while (es.reason != es.NEWT_EXIT_COMPONENT || es.u.co == lb || es.u.co == b2); newtFormDestroy(f); newtPopWindow(); return ret; }
// ======================================================= int CInterfaceNewt::guiInitMainWindow(char *szDevice, char *szImageFile, char *szNetworkIP, DWORD *dwServerPort, bool *bSsl) { newtComponent formMain, btnContinue, btnExit, btnAbout; newtComponent labelPartition, labelImage, editPartition, editImage, btnImage; newtComponent widgetTemp, labelAction, radioSave, radioRestore, radioMbr; newtComponent checkNetwork, labelNetwork, labelPort, editNetwork, editPort, checkSsl; newtExitStruct event; char szTemp[1024]; int nAction; int nRes; showDebug(8, "guiInitMainWindow\n"); SNPRINTF(szTemp, "Partition Image %s", PACKAGE_VERSION); newtCenteredWindow(67, 20, szTemp); labelPartition = newtLabel(1, 0, i18n("* Partition to save/restore")); editPartition = newtListbox(3, 1, 7, NEWT_FLAG_SCROLL); labelImage = newtLabel(1, 9, i18n("* Image file to create/use")); editImage = newtEntry(3, 10, szImageFile, 59, NULL, NEWT_FLAG_SCROLL); btnImage = newtCompactButton(62, 10, "*"); labelAction = newtLabel(1, 12, i18n("Action to be done:")); radioSave = newtRadiobutton(1, 13, i18n("Save partition into a new image file"), true, NULL); radioRestore = newtRadiobutton(1, 14, i18n("Restore partition from an image file"), false, radioSave); radioMbr = newtRadiobutton(1, 15, i18n("Restore an MBR from the image file"), false, radioRestore); checkNetwork = newtCheckbox(1, 17, i18n("Connect to server"), (!!(*szNetworkIP) ? 'X' : ' '), " X", NULL); #ifdef HAVE_SSL checkSsl = newtCheckbox(5, 19, i18n("Encrypt data on the network with SSL"), (*bSsl ? 'X' : ' '), " X", NULL); #else #ifdef MUST_LOGIN checkSsl = newtLabel(5, 19,i18n("SSL disabled at compile time")); #else checkSsl = newtLabel(5, 19,i18n("SSL&login disabled at compile time")); #endif #endif labelNetwork = newtLabel(5, 18, i18n("IP/name of the server:")); editNetwork = newtEntry(28, 18, szNetworkIP, 25, NULL, 0); labelPort = newtLabel(54, 18, i18n("Port:")); SNPRINTF(szTemp, "%u", *dwServerPort); editPort = newtEntry(60, 18, szTemp, 6, NULL, 0); btnContinue = newtCompactButton(50, 12, i18n("Next (F5)")); btnAbout = newtCompactButton(50, 14, i18n("About")); btnExit = newtCompactButton(50, 16, i18n("Exit (F6)")); nRes = fillPartitionList(editPartition); if (nRes == -1) RETURN_int(-1); formMain = newtForm(NULL, NULL, 0); newtFormAddComponents(formMain, labelPartition, labelImage, editPartition, editImage, btnImage, labelAction, radioSave, radioRestore, radioMbr, checkNetwork, labelNetwork, editNetwork, labelPort, editPort, checkSsl, btnContinue, btnAbout, btnExit, NULL); newtFormAddHotKey(formMain, KEY_EXIT); // Exit newtFormAddHotKey(formMain, KEY_OKAY); // Okay begin: /*widgetTemp = */newtFormRun(formMain, &event); widgetTemp = newtFormGetCurrent(formMain); if (((event.reason == event.NEWT_EXIT_HOTKEY) && (event.u.key == KEY_EXIT)) || ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnExit))) //if(widgetTemp == btnExit) return OPERATION_EXIT; if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnAbout)) { showAboutDialog(); goto begin; } if ((event.reason == event.NEWT_EXIT_COMPONENT) && (widgetTemp == btnImage)) { char *fs_; fs_=filesel(newtEntryGetValue(editImage)); if(fs_) { newtEntrySet(editImage, fs_, 1); // free(fs_); } goto begin; } if (strcmp(newtEntryGetValue(editImage), "") == 0) // if "image" field empty { msgBoxError(i18n("The \"Image\" field is empty. Cannot continue")); goto begin; } if (newtCheckboxGetValue(checkNetwork) == 'X') { if (!(*newtEntryGetValue(editNetwork))) { msgBoxError(i18n("The \"Server IP/Name\" field is empty. Cannot continue")); goto begin; } if (!atoi((char*)newtEntryGetValue(editPort))) { msgBoxError(i18n("The \"Server Port\" field is not a valid integer. Cannot continue")); goto begin; } } // get device strcpy(szDevice, (char*)newtListboxGetCurrent(editPartition)); // image file strcpy(szImageFile, newtEntryGetValue(editImage)); // network if (newtCheckboxGetValue(checkNetwork) == 'X') // If network is activated { strcpy(szNetworkIP, (char*)newtEntryGetValue(editNetwork)); *dwServerPort = atoi((char*)newtEntryGetValue(editPort)); #ifdef HAVE_SSL *bSsl = (newtCheckboxGetValue(checkSsl) == 'X'); #endif } else // no network { *szNetworkIP = 0; *dwServerPort = OPTIONS_DEFAULT_SERVERPORT; } nAction = 0; if (newtRadioGetCurrent(radioRestore) == radioSave) { nAction = OPERATION_SAVE; } else if (newtRadioGetCurrent(radioRestore) == radioRestore) { nAction = OPERATION_RESTORE; } else if (newtRadioGetCurrent(radioRestore) == radioMbr) { nAction = OPERATION_RESTMBR; } newtFormDestroy(formMain); newtPopWindow(); return nAction; }
/* setup hard drive based install from a partition with a filesystem and * ISO images on that filesystem */ char * mountHardDrive(struct installMethod * method, char * location, struct loaderData_s * loaderData) { int rc; int i; newtComponent listbox, label, dirEntry, form, okay, back, text; struct newtExitStruct es; newtGrid entryGrid, grid, buttons; int done = 0; char * dir = strdup(""); char * tmpDir; char * url = NULL; char * buf, *substr; int numPartitions; char **partition_list; char *selpart; char *kspartition = NULL, *ksdirectory = NULL; /* handle kickstart/stage2= data first if available */ if (loaderData->method == METHOD_HD && loaderData->stage2Data) { kspartition = ((struct hdInstallData *)loaderData->stage2Data)->partition; ksdirectory = ((struct hdInstallData *)loaderData->stage2Data)->directory; logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory); /* if exist, duplicate */ if (kspartition) kspartition = strdup(kspartition); if (ksdirectory) { ksdirectory = strdup(ksdirectory); } else { ksdirectory = strdup("/images/install.img"); } if (!kspartition || !ksdirectory) { logMessage(ERROR, "missing partition or directory specification"); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { /* if we start with /dev, strip it (#121486) */ char *kspart = kspartition; if (!strncmp(kspart, "/dev/", 5)) kspart = kspart + 5; url = setupIsoImages(kspart, ksdirectory, location); if (!url) { logMessage(ERROR, "unable to find %s installation images on hd", getProductName()); loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { free(kspartition); free(ksdirectory); return url; } } } else { kspartition = NULL; ksdirectory = NULL; } /* if we're here its either because this is interactive, or the */ /* hd kickstart directive was faulty and we have to prompt for */ /* location of harddrive image */ partition_list = NULL; while (!done) { /* if we're doing another pass free this up first */ if (partition_list) freePartitionsList(partition_list); partition_list = getPartitionsList(NULL); numPartitions = lenPartitionsList(partition_list); /* no partitions found, try to load a device driver disk for storage */ if (!numPartitions) { rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"), _("You don't seem to have any hard drives on " "your system! Would you like to configure " "additional devices?")); if (rc == 2) { loaderData->stage2Data = NULL; return NULL; } rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } /* now find out which partition has the stage2 image */ checked_asprintf(&buf, _("What partition and directory on that " "partition holds the installation image " "for %s? If you don't see the disk drive " "you're using listed here, press F2 to " "configure additional devices."), getProductName()); text = newtTextboxReflowed(-1, -1, buf, 62, 5, 5, 0); free(buf); listbox = newtListbox(-1, -1, numPartitions > 5 ? 5 : numPartitions, NEWT_FLAG_RETURNEXIT | (numPartitions > 5 ? NEWT_FLAG_SCROLL : 0)); for (i = 0; i < numPartitions; i++) newtListboxAppendEntry(listbox,partition_list[i],partition_list[i]); /* if we had ks data around use it to prime entry, then get rid of it*/ if (kspartition) { newtListboxSetCurrentByKey(listbox, kspartition); free(kspartition); kspartition = NULL; } label = newtLabel(-1, -1, _("Directory holding image:")); dirEntry = newtEntry(28, 11, dir, 28, (const char **) &tmpDir, NEWT_ENTRY_SCROLL); /* if we had ks data around use it to prime entry, then get rid of it*/ if (ksdirectory) { newtEntrySet(dirEntry, ksdirectory, 1); free(ksdirectory); ksdirectory = NULL; } entryGrid = newtGridHStacked(NEWT_GRID_COMPONENT, label, NEWT_GRID_COMPONENT, dirEntry, NEWT_GRID_EMPTY); buttons = newtButtonBar(_("OK"), &okay, _("Back"), &back, NULL); grid = newtCreateGrid(1, 4); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, entryGrid, 0, 0, 0, 1, 0, 0); newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); newtGridWrappedWindow(grid, _("Select Partition")); form = newtForm(NULL, NULL, 0); newtFormAddHotKey(form, NEWT_KEY_F2); newtFormAddHotKey(form, NEWT_KEY_F12); newtGridAddComponentsToForm(grid, form, 1); newtGridFree(grid, 1); newtFormRun(form, &es); selpart = newtListboxGetCurrent(listbox); free(dir); if (tmpDir && *tmpDir) { /* Protect from form free. */ dir = strdup(tmpDir); } else { dir = strdup(""); } newtFormDestroy(form); newtPopWindow(); if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == back) { loaderData->stage2Data = NULL; return NULL; } else if (es.reason == NEWT_EXIT_HOTKEY && es.u.key == NEWT_KEY_F2) { rc = loadDriverFromMedia(DEVICE_DISK, loaderData, 0, 0); continue; } logMessage(INFO, "partition %s selected", selpart); /* If the user-provided URL points at a repo instead of a stage2 * image, fix that up now. */ substr = strstr(dir, ".img"); if (!substr || (substr && *(substr+4) != '\0')) { checked_asprintf(&dir, "%s/images/install.img", dir); } loaderData->invalidRepoParam = 1; url = setupIsoImages(selpart, dir, location); if (!url) { newtWinMessage(_("Error"), _("OK"), _("Device %s does not appear to contain " "an installation image."), selpart, getProductName()); continue; } done = 1; } free(dir); return url; }