resource-manager.cpp revision c864652e7fca4ed7605835d5cb6661dc422cabaa
/*
* Inkscape::ResourceManager - tracks external resources such as image and css files.
*
* Copyright 2011 Jon A. Cruz <jon@joncruz.org>
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <string>
#include <vector>
#include <algorithm>
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include <glibmm/uriutils.h>
#include <gtkmm/recentmanager.h>
#include "resource-manager.h"
#include "document.h"
#include "sp-object.h"
#include "document-undo.h"
namespace Inkscape {
{
}
}
return parts;
}
{
// Whack the parts into pieces
// TODO debug g_message("+++++++++++++++++++++++++");
// TODO debug g_message(" [%s]", it->c_str());
}
// TODO debug g_message(" - - - - - - - - - - - - - - - ");
// TODO debug g_message(" [%s]", it->c_str());
}
// TODO debug g_message("+++++++++++++++++++++++++");
// Both paths have the same root. We can proceed.
}
// TODO debug g_message("+++++++++++++++++++++++++");
// TODO debug g_message(" [%s]", it->c_str());
}
// TODO debug g_message(" - - - - - - - - - - - - - - - ");
// TODO debug g_message(" [%s]", it->c_str());
}
// TODO debug g_message("+++++++++++++++++++++++++");
}
// TODO debug g_message("----> [%s]", result.c_str());
}
}
}
return result;
}
class ResourceManagerImpl : public ResourceManager {
public:
virtual ~ResourceManagerImpl();
/**
* Walk all links in a document and create a listing of unique broken links.
*
* @return a list of all broken links.
*/
/**
* Resolve broken links as a whole and return a map for those that can be found.
*
* Note: this will allow for future enhancements including relinking to new locations
* with the most broken files found, etc.
*
* @return a map of found links.
*/
std::map<Glib::ustring, Glib::ustring> locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks);
protected:
};
: ResourceManager()
{
}
{
}
{
bool isFile = false;
// TODO debug g_message("Scheme is now [%s]", scheme.c_str());
if ( scheme == "file" ) {
// TODO debug g_message("--- is a file URI [%s]", href.c_str());
// throws Glib::ConvertError:
// TODO debug g_message(" [%s]", uri.c_str());
isFile = true;
}
} else {
// No scheme. Assuming it is a file path (absolute or relative).
// throws Glib::ConvertError:
isFile = true;
}
return isFile;
}
{
if ( doc ) {
}
} else {
}
}
}
}
}
}
return result;
}
std::map<Glib::ustring, Glib::ustring> ResourceManagerImpl::locateLinks(Glib::ustring const & docbase, std::vector<Glib::ustring> const & brokenLinks)
{
// Note: we use a vector because we want them to stay in order:
for ( std::vector< Glib::RefPtr<Gtk::RecentInfo> >::iterator it = recentItems.begin(); it != recentItems.end(); ++it ) {
if ( scheme == "file" ) {
// TODO debug g_message(" ==>[%s]", path.c_str());
}
}
}
// At the moment we expect this list to contain file:// references, or simple relative or absolute paths.
for ( std::vector<Glib::ustring>::const_iterator it = brokenLinks.begin(); it != brokenLinks.end(); ++it ) {
// TODO debug g_message("========{%s}", it->c_str());
// We were able to get some path. Check it
// TODO debug g_message(" not absolute. Fixing up as [%s]", uri.c_str());
}
// TODO debug g_message(" DOES NOT EXIST.");
bool exists = false;
} else {
}
// TODO debug g_message(" [%s] [%s]%s", tmp.c_str(), remainder.c_str(), exists ? " XXXX" : "");
}
if ( !exists ) {
// TODO debug g_message("Expanding the search...");
// Check if the MRU bases point us to it.
for ( std::vector<std::string>::iterator it = priorLocations.begin(); !exists && (it != priorLocations.end()); ++it ) {
}
}
}
if ( exists ) {
// TODO debug g_message("Need to convert to relative if possible [%s]", remainder.c_str());
}
Glib::ustring replacement = isAbsolute ? Glib::filename_to_uri( remainder ) : Glib::filename_to_utf8( remainder );
}
}
}
}
return result;
}
{
bool changed = false;
if ( doc ) {
// TODO debug g_message("FIXUP FIXUP FIXUP FIXUP FIXUP FIXUP FIXUP FIXUP FIXUP FIXUP");
// TODO debug g_message(" base is [%s]", doc->getBase());
if ( !brokenHrefs.empty() ) {
// TODO debug g_message(" FOUND SOME LINKS %d", static_cast<int>(brokenHrefs.size()));
for ( std::vector<Glib::ustring>::iterator it = brokenHrefs.begin(); it != brokenHrefs.end(); ++it ) {
// TODO debug g_message(" [%s]", it->c_str());
}
}
for ( std::map<Glib::ustring, Glib::ustring>::iterator it = mapping.begin(); it != mapping.end(); ++it )
{
}
if ( href ) {
// TODO debug g_message(" consider [%s]", href);
// TODO debug g_message(" Found a replacement");
}
if (updated) {
// force immediate update of dependant attributes
updated->updateRepr();
}
changed = true;
}
}
}
if ( changed ) {
}
}
return changed;
}
static ResourceManagerImpl* theInstance = 0;
{
}
}
if ( !theInstance ) {
theInstance = new ResourceManagerImpl();
}
return *theInstance;
}
} // 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 :