コード例 #1
0
ファイル: nmt-newt-button.c プロジェクト: BtbN/NetworkManager
static newtComponent
nmt_newt_button_build_component (NmtNewtComponent *component,
                                 gboolean          sensitive)
{
	NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (component);
	newtComponent co;
	char *label = NULL, *label_lc;

	if (sensitive) {
		label_lc = nmt_newt_locale_from_utf8 (priv->label);
		co = newtCompactButton (-1, -1, label_lc);
		g_free (label_lc);
	} else {
		label = g_strdup_printf (" <%s>", priv->label);
		label_lc = nmt_newt_locale_from_utf8 (label);
		co = newtLabel (-1, -1, label_lc);
		g_free (label_lc);
		newtLabelSetColors (co, NMT_NEWT_COLORSET_DISABLED_BUTTON);
	}

	return co;
}
コード例 #2
0
/**
 * Pop up a list containing the filenames in @p source_file and the severity if they have changed since the
 * last backup. There can be no more than @p ARBITRARY_MAXIMUM files in @p source_file.
 * @param source_file The file containing a list of changed files.
 */
	void popup_changelist_from_file(char *source_file) {
		char *reason = NULL;
		newtComponent myForm;
		newtComponent bClose;
		newtComponent bSelect;
		newtComponent b_res;
		newtComponent fileListbox;
		newtComponent headerMsg;

		/*@ ???? ************************************************************ */
		void *curr_choice;
		void *keylist[ARBITRARY_MAXIMUM];

		/*@ int ************************************************************* */
		int i = 0;
		int currline = 0;
		int finished = FALSE;
		long lng = 0;

		/*@ buffers ********************************************************* */
		char *tmp;
		char *differ_sz;

		struct s_filelist *filelist;
		assert_string_is_neither_NULL_nor_zerolength(source_file);
		if (g_text_mode) {
			log_msg(2, "Text mode. Therefore, no popup list.");
			return;
		}
		log_msg(2, "Examining file %s", source_file);

		lng = count_lines_in_file(source_file);
		if (lng < 1) {
			log_msg(2, "No lines in file. Therefore, no popup list.");
			return;
		} else if (lng >= ARBITRARY_MAXIMUM) {
			log_msg(2, "Too many files differ for me to list.");
			return;
		}

		filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist));
		fileListbox =
			newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
		newtListboxClear(fileListbox);

		if (load_filelist_into_array(filelist, source_file)) {
			log_msg(2, "Can't open %s; therefore, cannot popup list",
					source_file);
			return;
		}
		log_msg(2, "%d files loaded into filelist array",
				filelist->entries);
		for (i = 0; i < filelist->entries; i++) {
			keylist[i] = (void *) i;
			newtListboxAppendEntry(fileListbox,
								   filelist_entry_to_string(&
															(filelist->
															 el[i])),
								   keylist[i]);
		}
		asprintf(&differ_sz,
				 _("  %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list."),
				 i);
		newtPushHelpLine(differ_sz);
		paranoid_free(differ_sz);

		bClose = newtCompactButton(10, 15, _(" Close  "));
		bSelect = newtCompactButton(30, 15, _(" Select "));
		asprintf(&tmp, "%-10s               %-20s", _("Priority"),
				 _("Filename"));
		headerMsg = newtLabel(2, 1, tmp);
		paranoid_free(tmp);

		newtOpenWindow(5, 4, 70, 16, _("Non-matching files"));
		myForm = newtForm(NULL, NULL, 0);
		newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
							  bSelect, NULL);
		while (!finished) {
			b_res = newtRunForm(myForm);
			if (b_res == bClose) {
				finished = TRUE;
			} else {
				curr_choice = newtListboxGetCurrent(fileListbox);
				for (i = 0;
					 i < filelist->entries && keylist[i] != curr_choice;
					 i++);
				if (i == filelist->entries && filelist->entries > 0) {
					log_to_screen(_("I don't know what that button does!"));
				} else {
					currline = i;
					if (filelist->entries > 0) {
						severity_of_difference(filelist->el[currline].
											   filename, reason);
						asprintf(&tmp, "%s --- %s",
								 filelist->el[currline].filename, reason);
						popup_and_OK(tmp);
						paranoid_free(tmp);
						paranoid_free(reason);
					}
				}
			}
		}
		newtFormDestroy(myForm);
		newtPopWindow();
		newtPopHelpLine();
	}
コード例 #3
0
ファイル: interface_newt.cpp プロジェクト: kohtala/partimage
// =======================================================
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;
}
コード例 #4
0
ファイル: interface_newt.cpp プロジェクト: kohtala/partimage
// 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;
}
コード例 #5
0
// =======================================================
void COptionsWindow::addButtons()
{
  m_btnOkay = newtCompactButton(7, 19, i18n("Continue (F5)"));
  m_btnExit = newtCompactButton(30, 19, i18n("Exit (F6)"));
  m_btnBack = newtCompactButton(52, 19, i18n("Main window (F7)"));
}