Exemplo n.º 1
0
/**
 * Callback to select a certificate
 */
void select_cert(HildonButton *button, gpointer user_data)
{
	GtkWidget *selector = hildon_file_chooser_dialog_new (GTK_WINDOW (user_data), GTK_FILE_CHOOSER_ACTION_OPEN);
	GtkWidget *nocert = hildon_button_new (HILDON_SIZE_FINGER_HEIGHT |
										   HILDON_SIZE_AUTO_WIDTH,
										   HILDON_BUTTON_ARRANGEMENT_VERTICAL);
	hildon_button_set_text (HILDON_BUTTON (nocert),
							"No certificate",
							"Use system-wide CA certificates");
	hildon_button_set_alignment (HILDON_BUTTON (nocert), 0, 0.5, 1, 1);
	g_signal_connect (nocert, "clicked", G_CALLBACK (no_certificate), selector);
	hildon_file_chooser_dialog_add_extra (HILDON_FILE_CHOOSER_DIALOG (selector),
										  nocert);
	gtk_widget_show_all (selector);

	switch (gtk_dialog_run (GTK_DIALOG (selector)))
	{
		case GTK_RESPONSE_OK:
		{
			gchar *file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selector));
			hildon_button_set_value (button, file);
			g_free(file);
			break;
		}
		case GTK_RESPONSE_REJECT:
		{
			hildon_button_set_value (button, "None");
			break;
		}
		default:
			break;
	}
	gtk_widget_destroy (selector);
}
Exemplo n.º 2
0
Arquivo: ui.c Projeto: senko/mawire
gchar *
show_filename_chooser (GtkWidget *window, gchar *folder)
{
  GtkWidget *dialog;
  gchar *result = NULL;

  dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window),
      GTK_FILE_CHOOSER_ACTION_OPEN);

  if (folder)
      gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), folder);

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
    {
      result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    }

  gtk_widget_destroy (dialog);

  return result;
}
Exemplo n.º 3
0
ZLGtkOpenFileDialog::ZLGtkOpenFileDialog(const std::string &title, const std::string &directoryPath, const std::string &filePath, const Filter &filter) {
	myDialog = HILDON_FILE_CHOOSER_DIALOG(hildon_file_chooser_dialog_new(
		0, GTK_FILE_CHOOSER_ACTION_OPEN
	));
	/*
	myDialog = GTK_DIALOG(gtk_file_chooser_dialog_new(
		title.c_str(), 0, GTK_FILE_CHOOSER_ACTION_OPEN,
		gtkString(ZLDialogManager::buttonName(ZLDialogManager::CANCEL_BUTTON)).c_str(),
			GTK_RESPONSE_CANCEL,
		gtkString(ZLDialogManager::buttonName(ZLDialogManager::OK_BUTTON)).c_str(),
			GTK_RESPONSE_ACCEPT,
		0
	));
	*/
	GtkFileChooser *chooser = GTK_FILE_CHOOSER(myDialog);
	gtk_file_chooser_set_current_folder(chooser, directoryPath.c_str());
	gtk_file_chooser_set_filename(chooser, filePath.c_str());
	GtkFileFilter *gtkFilter = gtk_file_filter_new();
	gtk_file_filter_add_custom(gtkFilter, (GtkFileFilterFlags)(GTK_FILE_FILTER_FILENAME | GTK_FILE_FILTER_MIME_TYPE), filterHandler, (void*)&filter, 0);
	gtk_file_chooser_set_filter(chooser, gtkFilter);
}
void XAP_UnixDialog_FileOpenSaveAs::runModal(XAP_Frame * pFrame)
{
    const XAP_StringSet * pSS = m_pApp->getStringSet();
    std::string szTitle;
    std::string szFileTypeLabel;

    switch (m_id)
    {
    case XAP_DIALOG_ID_INSERT_PICTURE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_Title, szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel, szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_OPEN:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_OpenTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_IMPORT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ImportTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERTMATHML:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertMath,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertMath,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERTOBJECT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertObject,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertObject,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERT_FILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_SAVEAS:
    case XAP_DIALOG_ID_FILE_SAVE_IMAGE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_SaveAsTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_FILE_EXPORT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ExportTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_PRINTTOFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_PrintToFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FilePrintTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_RECORDTOFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_REPLAYFROMFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    default:
        UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
        m_bSave = false;
        break;
    }

    // NOTE: we use our string mechanism to localize the dialog's
    // NOTE: title and the error/confirmation message boxes.  we
    // NOTE: let GTK take care of the localization of the actual
    // NOTE: buttons and labels on the FileSelection dialog.

    // Get the GtkWindow of the parent frame
    XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
    GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow();

    if(parent && (GTK_WIDGET_TOPLEVEL(parent) != TRUE))
    {
        parent = gtk_widget_get_toplevel (parent);
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    m_FC = GTK_FILE_CHOOSER( hildon_file_chooser_dialog_new(GTK_WINDOW(parent),
                             (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE))
                           );
#else
    m_FC = GTK_FILE_CHOOSER( gtk_file_chooser_dialog_new (szTitle.c_str(),
                             GTK_WINDOW(parent),
                             (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE),
                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                             (m_bSave ? GTK_STOCK_SAVE : GTK_STOCK_OPEN), GTK_RESPONSE_ACCEPT,
                             (gchar*)NULL)
                           );
#endif

    gtk_file_chooser_set_local_only(m_FC, FALSE);

    abiSetupModalDialog(GTK_DIALOG(m_FC), pFrame, this, GTK_RESPONSE_ACCEPT);
    GtkWidget * filetypes_pulldown = NULL;

    std::string s;

    /*
      Add a drop-down list of known types to facilitate a file-types selection.
      We store an indexer in the user data for each menu item in the popup, so
      we can read the type we need to return.
    */

    if (m_id == XAP_DIALOG_ID_INSERT_PICTURE)
    {
        GtkWidget * preview = createDrawingArea ();
        gtk_widget_show (preview);
        m_preview = preview;
        gtk_widget_set_size_request (preview, PREVIEW_WIDTH, PREVIEW_HEIGHT);

        // place the preview area inside a container to get a nice border
        GtkWidget * preview_hbox = gtk_hbox_new(FALSE, 0);
        gtk_container_set_border_width  (GTK_CONTAINER(preview_hbox), 4);
        gtk_box_pack_start(GTK_BOX(preview_hbox), preview, TRUE, TRUE, 0);

        // attach the preview area to the dialog
        gtk_file_chooser_set_preview_widget (m_FC, preview_hbox);
        gtk_file_chooser_set_preview_widget_active (m_FC, true);

        // connect some signals
        g_signal_connect (m_FC, "update_preview",
                          G_CALLBACK (file_selection_changed), static_cast<gpointer>(this));

        g_signal_connect (preview, "expose_event",
                          G_CALLBACK (s_preview_exposed), static_cast<gpointer>(this));
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    filetypes_pulldown = gtk_combo_box_new();
    gtk_widget_show(filetypes_pulldown);
    GtkWidget * pulldown_hbox = filetypes_pulldown;
#else
    // hbox for our pulldown menu (GTK does its pulldown this way */
    GtkWidget * pulldown_hbox = gtk_hbox_new(FALSE, 15);
    gtk_widget_show(pulldown_hbox);

    // pulldown label
    GtkWidget * filetypes_label = gtk_label_new_with_mnemonic(convertMnemonics(szFileTypeLabel).c_str());
    gtk_label_set_justify(GTK_LABEL(filetypes_label), GTK_JUSTIFY_RIGHT);
    gtk_misc_set_alignment(GTK_MISC(filetypes_label), 1.0, 0.5);
    gtk_widget_show(filetypes_label);
    gtk_box_pack_start(GTK_BOX(pulldown_hbox), filetypes_label, TRUE, TRUE, 0);

    // pulldown menu
    filetypes_pulldown = gtk_combo_box_new();
    gtk_widget_show(filetypes_pulldown);
    gtk_box_pack_end(GTK_BOX(pulldown_hbox), filetypes_pulldown, TRUE, TRUE, 0);
    gtk_label_set_mnemonic_widget(GTK_LABEL(filetypes_label), filetypes_pulldown);
#endif
    //
    // add the filters to the dropdown list
    //
    GtkComboBox* combo = GTK_COMBO_BOX(filetypes_pulldown);
    XAP_makeGtkComboBoxText(combo, G_TYPE_INT);

    // Auto-detect is always an option, but a special one, so we use
    // a pre-defined constant for the type, and don't use the user-supplied
    // types yet.
    pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileTypeAutoDetect,s);
    XAP_appendComboBoxTextAndInt(combo, s.c_str(), XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO);

    UT_sint32 activeItemIndex = -1;

    // add list items
    {
        UT_ASSERT(g_strv_length((gchar **) m_szSuffixes) == g_strv_length((gchar **) m_szDescriptions));

        // measure one list, they should all be the same length
        UT_uint32 end = g_strv_length((gchar **) m_szDescriptions);

        for (UT_uint32 i = 0; i < end; i++)
        {
            // If this type is default, save its index (i) for later use
            if (m_nTypeList[i] == m_nDefaultFileType)
                activeItemIndex = i;

            XAP_appendComboBoxTextAndInt(combo, m_szDescriptions[i], m_nTypeList[i]);
//
// Attach a callback when it is activated to change the file suffix
//
//			g_signal_connect(G_OBJECT(thismenuitem), "activate",
//							 G_CALLBACK(s_filetypechanged),
//							 reinterpret_cast<gpointer>(this));
        }
    }

    m_wFileTypes_PullDown = filetypes_pulldown;
    // dialog; open dialog always does auto-detect
    // TODO: should this also apply to the open dialog?
    if (m_id == XAP_DIALOG_ID_FILE_SAVEAS || m_id == XAP_DIALOG_ID_FILE_SAVE_IMAGE)
    {
        gtk_combo_box_set_active(combo, activeItemIndex + 1);
    }
    else
    {
        gtk_combo_box_set_active(combo, 0);
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    hildon_file_chooser_dialog_add_extra ((HildonFileChooserDialog*)m_FC,
                                          pulldown_hbox);
#else
    gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(m_FC), pulldown_hbox);
#endif

    // connect the signals for OK and CANCEL and the requisite clean-close signals
    g_signal_connect(G_OBJECT(m_FC),
                     "delete-event",
                     G_CALLBACK(s_delete_clicked),
                     this);

    g_signal_connect(G_OBJECT(m_FC),
                     "key_press_event",
                     G_CALLBACK(fsel_key_event), &m_answer);

    g_signal_connect (G_OBJECT (m_FC),
                      "response",
                      G_CALLBACK(dialog_response), &m_answer);

    g_signal_connect (G_OBJECT (m_FC),
                      "file-activated",
                      G_CALLBACK(s_file_activated), &m_answer);

    g_signal_connect(G_OBJECT(filetypes_pulldown), "changed",
                     G_CALLBACK(s_filetypechanged),
                     reinterpret_cast<gpointer>(this));

    // use the persistence info and/or the suggested filename
    // to properly seed the dialog.

    gchar * szPersistDirectory = NULL;	// we must g_free this

    if (!m_szInitialPathname || !*m_szInitialPathname)
    {
        // the caller did not supply initial pathname
        // (or supplied an empty one).  see if we have
        // some persistent info.

        UT_ASSERT(!m_bSuggestName);
        if (m_szPersistPathname)
        {
            // we have a pathname from a previous use,
            // extract the directory portion and start
            // the dialog there (but without a filename).

            szPersistDirectory = UT_go_dirname_from_uri(m_szPersistPathname, FALSE);
            gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory);
        }
        else
        {
            // no initial pathname given and we don't have
            // a pathname from a previous use, so just let
            // it come up in the current working directory.
        }
    }
    else
    {
        // we have an initial pathname (the name of the document
        // in the frame that we were invoked on).  if the caller
        // wanted us to suggest a filename, use the initial
        // pathname as is.  if not, use the directory portion of
        // it.

        if (m_bSuggestName)
        {
            xxx_UT_DEBUGMSG(("Iniitial filename is %s \n",m_szInitialPathname));
#if 0
            if (!g_path_is_absolute (m_szInitialPathname)) { // DAL: todo: is this correct?
                gchar *dir = g_get_current_dir ();
                gchar *file = m_szInitialPathname;
                gchar *filename = g_build_filename (dir, file, (gchar *)NULL);
                m_szInitialPathname = UT_go_filename_to_uri(filename);
                g_free(filename);
                g_free (dir);
                g_free (file);
            }
#endif
            if(m_id == XAP_DIALOG_ID_FILE_SAVEAS)
            {
                std::string szInitialSuffix = UT_pathSuffix(m_szInitialPathname);
                std::string szSaveTypeSuffix = IE_Exp::preferredSuffixForFileType(m_nDefaultFileType).utf8_str();
                if(!szInitialSuffix.empty() && !szSaveTypeSuffix.empty()
                        && (szSaveTypeSuffix != szInitialSuffix))
                {
                    std::string sFileName = m_szInitialPathname;
                    std::string::size_type i = sFileName.find_last_of('.');

                    if(i != std::string::npos)
                    {
                        // erase to the end()
                        sFileName.erase(i);
                        sFileName += szSaveTypeSuffix;
                        FREEP(m_szInitialPathname);
                        m_szInitialPathname = g_strdup(sFileName.c_str());
                    }
                }
            }
            if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname))
            {
                gtk_file_chooser_set_uri(m_FC, m_szInitialPathname);
            }
        }
        else
        {
            if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname))
            {
                szPersistDirectory = UT_go_dirname_from_uri(m_szInitialPathname, FALSE);
                gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory);
            }
            else
            {
                // we are dealing with a plain filename, not an URI or path, so
                // just let it come up in the current working directory.
            }
        }
    }

    // center the dialog
    xxx_UT_DEBUGMSG(("before center IS WIDGET_TOP_LEVL %d \n",(GTK_WIDGET_TOPLEVEL(parent))));
    xxx_UT_DEBUGMSG(("before center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent))));
    centerDialog(parent, GTK_WIDGET(m_FC));
    xxx_UT_DEBUGMSG(("After center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent))));

    gtk_widget_show(GTK_WIDGET(m_FC));
    gtk_grab_add(GTK_WIDGET(m_FC));

    bool bResult = _run_gtk_main(pFrame,filetypes_pulldown);

    if (bResult)
    {
        UT_ASSERT(m_szFinalPathnameCandidate);

        // store final path name and file type
        m_szFinalPathname = g_strdup(m_szFinalPathnameCandidate);

        FREEP(m_szFinalPathnameCandidate);

        // what a long ugly line of code
        m_nFileType = XAP_comboBoxGetActiveInt(GTK_COMBO_BOX(filetypes_pulldown));
    }

    if (m_FC != NULL) {
        gtk_grab_remove (GTK_WIDGET(m_FC));
        gtk_widget_destroy (GTK_WIDGET(m_FC));
        m_FC = NULL;
        FREEP(szPersistDirectory);
    }

    return;
}