ocaldialogs.cpp revision e29b93a8fdcabf567e480457a740b33966924071
/**
* @file
* 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
//#########################################################################
{
}
{
}
{
set_visible_window(false);
draw_spinner = false;
spinner_step = 0;
}
{
// Draw shadow
int x = get_allocation().get_x();
int y = get_allocation().get_y();
if (draw_spinner) {
int spinner_size = 16;
// FIXME: Gtk::Style::paint_spinner not yet in gtkmm
}
return false;
}
void LoadingBox::start()
{
// Timeout hasn't been stopped, so must be disconnected
}
draw_spinner = true;
}
void LoadingBox::stop()
{
draw_spinner = false;
}
bool LoadingBox::on_timeout() {
if (draw_spinner) {
if (spinner_step == 11) {
spinner_step = 0;
} else {
spinner_step ++;
}
queue_draw();
return true;
}
return false;
}
{
box_loading = new LoadingBox();
label_title = new WrapLabel();
label_description = new WrapLabel();
label_time = new WrapLabel();
pack_start(*box_loading, false, false);
pack_start(*image, false, false);
pack_start(*label_title, false, false);
pack_start(*label_description, false, false);
pack_start(*label_time, false, false);
label_title->set_line_wrap(true);
label_description->set_line_wrap(true);
label_time->set_line_wrap(true);
box_loading->set_no_show_all(true);
image->set_no_show_all(true);
set_border_width(12);
clear();
}
{
}
void PreviewWidget::show_box_loading()
{
box_loading->show();
box_loading->start();
}
void PreviewWidget::hide_box_loading()
{
box_loading->hide();
box_loading->stop();
}
{
}
void PreviewWidget::clear()
{
box_loading->hide();
}
{
// Draw background
int x = get_allocation().get_x();
int y = get_allocation().get_y();
return false;
}
{
image->set_no_show_all(true);
spinner->set_no_show_all(true);
label->set_no_show_all(true);
pack_start(*image, false, false);
pack_start(*spinner, false, false);
pack_start(*label, false, false);
}
void StatusWidget::clear()
{
}
{
}
{
}
{
show_all();
}
void StatusWidget::end_process()
{
clear();
}
{
}
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 {
}
}
{
set_visible_window(false);
}
{
// Draw background and shadow
int x = get_allocation().get_x();
int y = get_allocation().get_y();
return false;
}
{
// 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;
}
set_visible_window(false);
}
{
if (draw_logo) {
int x = get_allocation().get_x();
int y = get_allocation().get_y();
// Draw logo, we mask [read fill] it with the mid colour from the
// user's GTK theme
}
return false;
}
{
set_headers_visible(false);
"markup", RESULTS_COLUMN_MARKUP);
// Hide all columns except for the MARKUP column
for (int i = 0; i < RESULTS_COLUMN_LENGTH; i++) {
if (i != RESULTS_COLUMN_MARKUP) {
get_column(i)->set_visible(false);
}
}
}
{
// If nothing is selected, then return
return;
}
}
void ImportDialog::on_button_import_clicked() {
// If nothing is selected, then return
return;
}
button_import->set_sensitive(false);
button_close->hide();
button_cancel->show();
}
/*
* Callback for cursor change
*/
{
// If nothing is selected, then return
return;
}
if (downloading_thumbnail) {
cancelled_thumbnail = true;
}
downloading_thumbnail = true;
}
{
preview_files->clear();
}
{
"openclipart");
if (type == TYPE_THUMBNAIL) {
} else {
}
}
void ImportDialog::create_temporary_dirs()
{
// Make sure the temporary directories exists, if not, create them
}
}
}
{
// Get Temporary Directory
// Make a unique filename for the clipart, in the form 'GUID.extension'
if (type == TYPE_IMAGE) {
} else {
}
// If the file has already been downloaded, use it
if (type == TYPE_IMAGE) {
on_image_downloaded(path, true);
} else {
on_thumbnail_downloaded(path, true);
}
return;
}
// Get Remote File URL and get the respective cancellable object
if (type == TYPE_IMAGE) {
} else {
}
// Download it asynchronously
}
{
bool success;
try {
success = false;
}
if (resource == TYPE_IMAGE) {
} else {
}
}
{
button_import->set_sensitive(true);
button_close->show();
button_cancel->hide();
// If anything went wrong, show an error message if the user didn't do it
if (!success && !cancelled_image) {
}
if (!success) {
widget_status->clear();
return;
}
try {
widget_status->clear();
success = false;
}
cancelled_image = false;
}
{
downloading_thumbnail = false;
// If anything went wrong, show an error message if the user didn't do it
if (!success && !cancelled_thumbnail) {
return;
}
if (!success) {
widget_status->clear();
return;
}
try {
widget_status->clear();
success = false;
}
cancelled_thumbnail = false;
}
/*
* Callback for row activated
*/
{
}
/**
* 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
*/
void ImportDialog::on_button_search_clicked()
{
}
void ImportDialog::on_button_close_clicked()
{
hide();
}
void ImportDialog::on_button_cancel_clicked()
{
cancelled_image = true;
}
/**
* Callback for user input into entry_search
*/
{
preview_files->clear();
// 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) {
return;
}
// Create the resulting xml document tree
// Initialize libxml and test mistakes between compiled and shared library used
// If nothing is returned, no results could be found
if (length == 0) {
} else {
}
return;
}
// Get the root element node
// Clear and populate the list_results
// 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
}
{
"<span size=\"large\">%1 <b>%2</b> %3</span>\n<span color=\"%4\">%5</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 PreviewWidget();
/// Add the buttons in the bottom of the dialog
drawingarea_logo = new LogoArea();
widget_status = new StatusWidget();
downloading_thumbnail = false;
cancelled_thumbnail = false;
cancelled_image = false;
// Packing
// Properties
set_border_width(12);
button_import->set_sensitive(false);
preview_files->clear();
/// Add the listview inside a ScrolledWindow
/// Only show the scrollbars when they are necessary
label_not_found->set_line_wrap(true);
notebook_content->set_show_tabs(false);
notebook_content->set_show_border(false);
button_cancel->set_no_show_all(true);
button_close->set_no_show_all(true);
button_close->show();
button_cancel->hide();
// Signals
// Create the temporary directories that will be needed later
}
/**
* Destructor
*/
{
}
/**
* Get the file extension type that was selected by the user. Valid after an [OK]
*/
{
return extension;
}
{
return m_signal_response;
}
} //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 :