ocaldialogs.cpp revision 6a6f3c63ce0a62119045fe2748bb61dfd4d94a58
/** @file
* @brief Open Clip Art Library integration dialogs - implementation
*/
/* Authors:
* Bruno Dilly
* Other dudes from The Inkscape Organization
* Andrew Higginson
*
* Copyright (C) 2007 Bruno Dilly <bruno.dilly@gmail.com>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h> // rename()
#include <unistd.h> // close()
#include <errno.h> // errno
#include <string.h> // strerror()
#include "path-prefix.h"
#include "ocaldialogs.h"
#include "filedialogimpl-gtkmm.h"
#include "interface.h"
#include "gc-core.h"
#include <dialogs/dialog-events.h>
#include "preferences.h"
namespace Inkscape
{
namespace UI
{
namespace Dialog
{
namespace OCAL
{
//########################################################################
//# F I L E E X P O R T T O O C A L
//########################################################################
/**
* Callback for fileNameEntry widget
*/
/*
void ExportDialog::fileNameEntryChangedCallback()
{
if (!fileNameEntry)
return;
Glib::ustring fileName = fileNameEntry->get_text();
if (!Glib::get_charset()) //If we are not utf8
fileName = Glib::filename_to_utf8(fileName);
myFilename = fileName;
response(Gtk::RESPONSE_OK);
}
*/
/**
* Constructor
*/
/*
ExportDialog::ExportDialog(Gtk::Window &parentWindow,
FileDialogType fileTypes,
const Glib::ustring &title) :
FileDialogBase(title, parentWindow)
{
*/
/*
* Start Taking the vertical Box and putting a Label
* and a Entry to take the filename
* Later put the extension selection and checkbox (?)
*/
/* Initalize to Autodetect */
/*
extension = NULL;
*/
/* No filename to start out with */
/*
myFilename = "";
*/
/* Set our dialog type (save, export, etc...)*/
/*
dialogType = fileTypes;
Gtk::VBox *vbox = get_vbox();
Gtk::Label *fileLabel = new Gtk::Label(_("File"));
fileNameEntry = new Gtk::Entry();
fileNameEntry->set_text(myFilename);
fileNameEntry->set_max_length(252); // I am giving the extension approach.
fileBox.pack_start(*fileLabel);
fileBox.pack_start(*fileNameEntry, Gtk::PACK_EXPAND_WIDGET, 3);
vbox->pack_start(fileBox);
//Let's do some customization
fileNameEntry = NULL;
Gtk::Container *cont = get_toplevel();
std::vector<Gtk::Entry *> entries;
findEntryWidgets(cont, entries);
if (entries.size() >=1 )
{
//Catch when user hits [return] on the text field
fileNameEntry = entries[0];
fileNameEntry->signal_activate().connect(
sigc::mem_fun(*this, &ExportDialog::fileNameEntryChangedCallback) );
}
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
show_all_children();
}
*/
/**
* Destructor
*/
/*
ExportDialog::~ExportDialog()
{
}
*/
/**
* Show this dialog modally. Return true if user hits [OK]
*/
/*
bool
ExportDialog::show()
{
set_modal (TRUE); //Window
sp_transientize((GtkWidget *)gobj()); //Make transient
gint b = run(); //Dialog
hide();
if (b == Gtk::RESPONSE_OK)
{
return TRUE;
}
else
{
return FALSE;
}
}
*/
/**
* Get the file name chosen by the user. Valid after an [OK]
*/
/*
Glib::ustring
ExportDialog::get_filename()
{
myFilename = fileNameEntry->get_text();
if (!Glib::get_charset()) //If we are not utf8
myFilename = Glib::filename_to_utf8(myFilename);
return myFilename;
}
void
ExportDialog::change_title(const Glib::ustring& title)
{
this->set_title(title);
}
*/
//########################################################################
//# F I L E E X P O R T T O O C A L P A S S W O R D
//########################################################################
/**
* Constructor
*/
/*
ExportPasswordDialog::ExportPasswordDialog(Gtk::Window &parentWindow,
const Glib::ustring &title) : FileDialogBase(title, parentWindow)
{
*/
/*
* Start Taking the vertical Box and putting 2 Labels
* and 2 Entries to take the username and password
*/
/* No username and password to start out with */
/*
myUsername = "";
myPassword = "";
Gtk::VBox *vbox = get_vbox();
Gtk::Label *userLabel = new Gtk::Label(_("Username:"));
Gtk::Label *passLabel = new Gtk::Label(_("Password:"));
usernameEntry = new Gtk::Entry();
usernameEntry->set_text(myUsername);
usernameEntry->set_max_length(255);
passwordEntry = new Gtk::Entry();
passwordEntry->set_text(myPassword);
passwordEntry->set_max_length(255);
passwordEntry->set_invisible_char('*');
passwordEntry->set_visibility(false);
passwordEntry->set_activates_default(true);
userBox.pack_start(*userLabel);
userBox.pack_start(*usernameEntry, Gtk::PACK_EXPAND_WIDGET, 3);
vbox->pack_start(userBox);
passBox.pack_start(*passLabel);
passBox.pack_start(*passwordEntry, Gtk::PACK_EXPAND_WIDGET, 3);
vbox->pack_start(passBox);
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
set_default(*add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK));
show_all_children();
}
*/
/**
* Destructor
*/
/*
ExportPasswordDialog::~ExportPasswordDialog()
{
}
*/
/**
* Show this dialog modally. Return true if user hits [OK]
*/
/*
bool
ExportPasswordDialog::show()
{
set_modal (TRUE); //Window
sp_transientize((GtkWidget *)gobj()); //Make transient
gint b = run(); //Dialog
hide();
if (b == Gtk::RESPONSE_OK)
{
return TRUE;
}
else
{
return FALSE;
}
}
*/
/**
* Get the username. Valid after an [OK]
*/
/*
Glib::ustring
ExportPasswordDialog::getUsername()
{
myUsername = usernameEntry->get_text();
return myUsername;
}
*/
/**
* Get the password. Valid after an [OK]
*/
/*
Glib::ustring
ExportPasswordDialog::getPassword()
{
myPassword = passwordEntry->get_text();
return myPassword;
}
void
ExportPasswordDialog::change_title(const Glib::ustring& title)
{
this->set_title(title);
}
*/
//#########################################################################
//### F I L E I M P O R T F R O M O C A L
//#########################################################################
{
}
void SearchEntry::_on_icon_pressed(Gtk::EntryIconPosition icon_position, const GdkEventButton* event)
{
grab_focus();
set_text("");
select_region(0, -1);
grab_focus();
}
}
void SearchEntry::_on_changed()
{
} else {
}
}
{
// Try to load the OCAL logo, but if the file is not found, degrade gracefully
try {
draw_logo = true;
} catch( Cairo::logic_error ) {
draw_logo = false;
}
}
void LogoDrawingArea::_on_realize()
{
}
{
// Draw background and shadow
if (draw_logo) {
// Draw logo, we mask [read fill] it with the mid colour from the
// user's GTK theme
// Draw text
}
return false;
}
{
myLabel = &description;
set_headers_visible(false);
"markup", RESULTS_COLUMN_MARKUP);
}
/*
* Callback for cursor chage
*/
void SearchResultList::on_cursor_changed()
{
// FIXME: this would be better as a per-user OCAL cache of files
// instead of filling /tmp with downloads.
// Create file path
if (fd<0) {
g_warning("Error creating temp file");
return;
}
// make sure we don't collide with other users on the same machine
// rename based on original image's name, retaining extension
goto failquit;
}
//get file url
//Inkscape::Preferences *prefs = Inkscape::Preferences::get();
//Glib::ustring fileUrl = "dav://"; //dav url
//fileUrl.append("/dav.php/");
//fileUrl.append(row[results_columns.CREATOR]); //author dir
//fileUrl.append("/");
//fileUrl.append(row[results_columns.FILENAME]); //filename
{
// open the temp file to receive
if (result == GNOME_VFS_ERROR_NOT_FOUND){
result = gnome_vfs_create (&to_handle, myFilename.c_str(), GNOME_VFS_OPEN_WRITE, FALSE, GNOME_VFS_PERM_USER_ALL);
}
if (result != GNOME_VFS_OK) {
g_warning("Error creating temp file '%s': %s", myFilename.c_str(), gnome_vfs_result_to_string(result));
goto fail;
}
if (result != GNOME_VFS_OK) {
g_warning("Could not find the file in Open Clip Art Library.");
goto fail;
}
// copy the file
while (1) {
break;
}
if (result != GNOME_VFS_OK) {
goto fail;
}
if (result != GNOME_VFS_OK) {
goto fail;
}
if (bytes_read != bytes_written){
g_warning("Bytes read not equal to bytes written");
goto fail;
}
}
}
return;
fail:
myFilename = "";
}
/*
* Callback for row activated
*/
void SearchResultList::on_row_activated(const Gtk::TreeModel::Path& /*path*/, Gtk::TreeViewColumn* /*column*/)
{
this->on_cursor_changed();
}
/*
* Returns the selected filename
*/
{
return myFilename;
}
/**
* Prints the names of the all the xml elements
* that are siblings or children of a given xml node
*/
{
// Get items information
{
{
}
{
}
{
char* creator = (char*) xml_creator;
}
{
//char* final_description;
stripped_description = _("No description");
}
//GRegex* regex = g_regex_new(g_regex_escape_string(stripped_description, -1));
//final_description = g_regex_replace_literal(regex, "\n", -1, 0, " ");
}
{
}
{
char* thumbnail_url = (char*) xml_thumbnail_url;
}
}
}
}
/**
* Callback for user input into entry_search
*/
{
// Create the URI to the OCAL RSS feed
// If we are not UTF8
if (!Glib::get_charset()) {
}
// Open the rss feed
}
{
char* data;
if (!sucess) {
sp_ui_error_dialog(_("Failed to receive the Open Clip Art Library RSS feed. Verify if the server name is correct in Configuration->Import/Export (e.g.: openclipart.org)"));
return;
}
// Create the resulting xml document tree
// Initialize libxml and test mistakes between compiled and shared library used
sp_ui_error_dialog(_("Server supplied malformed Clip Art feed"));
return;
}
// get the root element node
// clear the list_results
if (list_results->size() == 0) {
} else {
// Populate the MARKUP column with the title & description of the clipart
}
}
// free the document
// free the global variables that may have been allocated by the parser
}
{
char* markup = g_markup_printf_escaped(
"<span size=\"large\">%s<b>%s</b>%s</span>\n<span color=\"%s\">%s</span>",
_("Please make sure all keywords are spelled correctly, or try again with different keywords."));
}
/**
* Constructor. Not called directly. Use the factory.
*/
{
// Initalize to Autodetect
// No filename to start out with
// Creation
entry_search = new SearchEntry();
preview_files = new SVGPreview();
/// Add the buttons in the bottom of the dialog
drawingarea_logo = new LogoDrawingArea();
// Packing
// Properties
set_border_width(12);
/// Add the listview inside a ScrolledWindow
/// Only show the scrollbars when they are necessary
notebook_content->set_show_tabs(false);
notebook_content->set_show_border(false);
// Signals
}
/**
* Destructor
*/
{
}
/**
* Show this dialog modally. Return true if user hits [OK]
*/
bool ImportDialog::show()
{
hide();
if (b == Gtk::RESPONSE_OK)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
* Get the file extension type that was selected by the user. Valid after an [OK]
*/
{
return extension;
}
/**
* Get the file name chosen by the user. Valid after an [OK]
*/
ImportDialog::get_filename (void)
{
return list_results->get_filename();
}
} //namespace OCAL
} //namespace Dialog
} //namespace UI
} //namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :