Ejemplo n.º 1
0
int open_ants(Widget w, char *fn, char *cmd)
{
    Widget list;
    Arg wargs[10];
    XmString *xmstr;
    char *p;
    string stmp, buf, user;
    int i, n, nindx, df, rec=0, bl_len;
    int err;
    size_t size;
    FILE *pdf;
    static ANTS ants;
    
    void send_line();
    char *getScanStr();
    
    strcpy(dfilname, fn);
    strcpy(stmp, fn);
    
    p = strtok(stmp, "/");
    while (p) {
        strcpy(buf, p);
        p = strtok(NULL, "/");
    }
    
    sscanf(buf, "DF%2d%4d.%s", &df, &bl_len, user);
    
    if (bl_len == 0) bl_len = 3;

    pdf = OpenDfil(df, bl_len, user, dfilname);
    if (!pdf) {
        sprintf(buf, "Open POPS file: cannot open dfile %s.", dfilname);
        send_line(buf);
        return 1;
    }
    
    nindx = ReadDfilIndex(pdf, indx);
    if (nindx <= 0) {
        if (nindx == 0) {
            sprintf(buf, "Open POPS file: dfile %s is empty.", dfilname);
        } else {
            sprintf(buf, "Open POPS file: dfile %s is corrupt.", dfilname);
        }
        send_line(buf);
        fclose(pdf);
        return 1;
    }
    
    i = 0;
    while (i < 500 && indx[i] != 0) {
        i++;
    }
    nindx = i;
    
    sprintf(buf, "POPS dfile %s (%d scans) is opened.", dfilname, nindx);
    send_line(buf);
    
    size = (size_t)(bl_len*DFILBLOCK)*sizeof(DFWORD);
    if (!itwh)
        itwh = (DFWORD *)malloc(size);
    else
        itwh = (DFWORD *)realloc(itwh, size);
    if (!itwh) {
        sprintf(buf, "Open POPS -- can't allocate itwh[%d]",
                bl_len*DFILBLOCK);
        send_line(buf);
        fclose(pdf);
        return 1;
    }
    
    strcpy(type_of_seq, cmd);
    
    if (strcmp(cmd, "mapants2") == 0 ||
        strcmp(cmd, "ants2")    == 0 ||
        strcmp(cmd, "seqants2") == 0 ||
        strcmp(cmd, "appmapants2") == 0 ||
        strcmp(cmd, "appseqants2") == 0)
        rec = 1;

    ants.pdf    = pdf;
    ants.bl_len = bl_len;
    ants.df     = df;
    ants.rec    = rec;
    ants.fname  = dfilname;
    ants.nscans = nindx;
    
    xmstr = (XmString *) XtMalloc(nindx * sizeof(XmString));
    if (!xmstr) {
        sprintf(buf, "Open POPS -- can't allocate xmstr[%d]", nindx);
        send_line(buf);
        fclose(pdf);
        return 1;
    }

    for (i=0; i<nindx; i++) {
        err = GetDfilBlock(pdf, i+1, bl_len, itwh);
        if (err != 0) {
            sprintf(buf, "Open POPS -- can't read read block %d", i+1);
            send_line(buf);
            fclose(pdf);
            return ret_open_ants(xmstr, nindx, err);
        }
        filltwh(&OnScan, &XScan, rec); 
        OnScan.Slength = HEADER + 2*OnScan.NChannel;
        xmstr[i] = MKSTRING(getScanStr(i));
    }

    n = 0;
    if (nindx > 0) {
        XtSetArg(wargs[n], XmNitemCount, nindx); n++;
        XtSetArg(wargs[n], XmNitems, xmstr); n++;
        if (nindx <= 30) {
            XtSetArg(wargs[n], XmNvisibleItemCount, nindx); n++;
        } else {
            XtSetArg(wargs[n], XmNvisibleItemCount, 30); n++;
        }
    }
    XtSetArg(wargs[n], XmNfontList, gp->flist10); n++;
    if (strncmp(cmd, "mapants", 7)==0 ||
        strncmp(cmd, "seqants", 7)==0 ||
        strncmp(cmd, "appmapants", 10)==0 ||
        strncmp(cmd, "appseqants", 10)==0) {
        XtSetArg(wargs[n], XmNselectionPolicy, XmEXTENDED_SELECT); n++;
    }
    
    list = create_list_dialog(w, dfilname, &ants, wargs, n);

    if (strncmp(cmd, "mapants", 7)==0 ||
        strncmp(cmd, "seqants", 7)==0 ||
        strncmp(cmd, "appmapants", 10)==0 ||
        strncmp(cmd, "appseqants", 10)==0) {
        XtAddCallback(list, XmNextendedSelectionCallback,
                      (XtCallbackProc)selectCB, &ants);
        XtAddCallback(list, XmNmultipleSelectionCallback,
                      (XtCallbackProc)selectCB, &ants);
    } else
        XtAddCallback(list, XmNbrowseSelectionCallback,
                      (XtCallbackProc)selectCB, &ants);

    return ret_open_ants(xmstr, nindx, 0);
}
Ejemplo n.º 2
0
/**
 * main callback for control panel plugins
 */
osso_return_t execute(osso_context_t *osso, gpointer data,
					  gboolean user_activated)
{
	gint response;

	create_list_dialog (data);

	if (!user_activated)
	{
		/* load state */
	}

	do
	{
		gchar *selected;
		response = gtk_dialog_run (GTK_DIALOG (ListDialog.dialog));
		switch (response)
		{
			case RESPONSE_NEW:
			{
				edit_connection (data, NULL);
				break;
			}
			case RESPONSE_EDIT:
			{
				StrongswanConnection *conn;
				selected = get_selected ();
				conn = strongswan_connections_get_connection (ListDialog.conns,
															  selected);
				if (conn)
				{
					edit_connection (data, conn);
				}
				else
				{
					hildon_banner_show_information (NULL, NULL,
												"Select a connection first");
				}
				g_free (selected);
				break;
			}
			case RESPONSE_DELETE:
			{
				GtkWidget *confirm;
				gint retval;
				gchar *msg;
				selected = get_selected ();
				if (!selected)
				{
					hildon_banner_show_information (NULL, NULL,
												"Select a connection first");
					break;
				}
				msg = g_strdup_printf ("Delete connection?\n%s", selected);
				confirm = hildon_note_new_confirmation (data, msg);
				retval = gtk_dialog_run (GTK_DIALOG (confirm));
				if (retval == GTK_RESPONSE_OK)
				{
					strongswan_connections_remove_connection (ListDialog.conns,
															  selected);
				}
				gtk_widget_destroy (confirm);
				g_free (msg);
				g_free (selected);
				break;
			}
			default:
				break;
		}
	}
	while (response > 0);

	gtk_widget_destroy (ListDialog.dialog);
	g_object_unref (ListDialog.conns);
	return OSSO_OK;
}