示例#1
0
/**
 * Append our subdirectories to the Application Path for this
 * application
 */  
bool RegistryTool::setPathInfo()
{
    Glib::ustring fullPath;
    Glib::ustring path;
    Glib::ustring exeName;

    if (!getExeInfo(fullPath, path, exeName))
        return false;

    //printf("full:'%s' path:'%s' exe:'%s'\n",
    //    fullPath.c_str(), path.c_str(), exeName.c_str());

    Glib::ustring keyName =
    "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\";
    keyName.append(exeName);

    Glib::ustring valueName = "";
    Glib::ustring value     = fullPath;

    if (!setStringValue(keyName, valueName, value))
        return false;

    //add our subdirectories
    Glib::ustring appPath = path;
    appPath.append("\\python;");
    appPath.append(path);
    appPath.append("\\perl");
    valueName = "Path";
    value     = appPath;

    if (!setStringValue(keyName, valueName, value))
        return false;

    return true;
}
示例#2
0
gchar *
sp_repr_css_write_string(SPCSSAttr *css)
{
    Glib::ustring buffer;

    for ( List<AttributeRecord const> iter = css->attributeList() ;
          iter ; ++iter )
    {
        if (iter->value && !strcmp(iter->value, "inkscape:unset")) {
            continue;
        }

        buffer.append(g_quark_to_string(iter->key));
        buffer.push_back(':');
        if (!strcmp(g_quark_to_string(iter->key), "font-family")
                || !strcmp(g_quark_to_string(iter->key), "-inkscape-font-specification")) {
            // we only quote font-family/font-specification, as SPStyle does
            gchar *t = g_strdup (iter->value);
            g_free (t);
            gchar *val_quoted = css2_escape_quote (iter->value);
            if (val_quoted) {
                buffer.append(val_quoted);
                g_free (val_quoted);
            }
        } else {
            buffer.append(iter->value); // unquoted
        }

        if (rest(iter)) {
            buffer.push_back(';');
        }
    }

    return (buffer.empty() ? NULL : g_strdup (buffer.c_str()));
}
示例#3
0
/*  --------------------------------------------------------  */
void Menu::saveAs_saveAsButton_clicked_cb()
{
    Glib::ustring ext(".xcs");

    if(!this->saveAsFile)
        Log::LogWarn(LEVEL_LOG_WARNING, "SaveAs Button panic !", __FILE__, __LINE__);
    

    Glib::ustring fileName = this->entryFileName->get_text();
    fileName.append(ext);

    Glib::ustring pathName = this->saveAsFile->get_current_folder();
    pathName.append("/");
    pathName.append(fileName);

    std::ofstream file(pathName.c_str(), std::ios::out);

    if(file.is_open()) {
        Glib::ustring text = mainWindow->get_text_editor()->get_buffer()->get_text();

        file << text;
    }

    file.close();

    this->saveAsFile->hide();
}
示例#4
0
gchar* Inkscape::IO::sanitizeString( gchar const * str )
{
    gchar *result = NULL;
    if ( str ) {
        if ( g_utf8_validate(str, -1, NULL) ) {
            result = g_strdup(str);
        } else {
            guchar scratch[8];
            Glib::ustring buf;
            guchar const *ptr = (guchar const*)str;
            while ( *ptr )
            {
                if ( *ptr == '\\' )
                {
                    buf.append("\\\\");
                } else if ( *ptr < 0x80 ) {
                    buf += (char)(*ptr);
                } else {
                    g_snprintf((gchar*)scratch, sizeof(scratch), "\\x%02x", *ptr);
                    buf.append((const char*)scratch);
                }
                ptr++;
            }
            result = g_strdup(buf.c_str());
        }
    }
    return result;
}
/* Method save_xml */
void ClusterSettings::save_xml (const Glib::ustring& filename)
{
  /* Create xml document */
  TiXmlDocument doc;

  /* XML Declaration */
  TiXmlDeclaration *decl = new TiXmlDeclaration ("0.0", "", "");
  doc.LinkEndChild (decl);

  /* Root element */
  TiXmlElement *root = new TiXmlElement ("SensorsClusterSettings");
  doc.LinkEndChild (root);

  /* Comment */
  Glib::ustring message;
  message.assign (" File created by ComLibSim at [");
  message.append (filename);
  message.append ("] ");
  TiXmlComment *comment = new TiXmlComment ();
  comment->SetValue (message.c_str ());
  root->LinkEndChild (comment);

  /* Cluster element */
  TiXmlElement *cluster = new TiXmlElement ("Cluster");
  root->LinkEndChild (cluster);

  /* Set cluster attribute */
  cluster->SetAttribute ("name", m_Name.c_str ());

  /* Sensors element */
  TiXmlElement *sensorsNode = new TiXmlElement ("Sensors");
  root->LinkEndChild (sensorsNode);

  /* Set sensor element and attributes */
  std::list<SensorSettings>::iterator iter;
  for (iter=m_Sensors.begin (); iter != m_Sensors.end (); iter++)
  {
    const SensorSettings& sensor_iter = *iter;

    /* Sensor element */
    TiXmlElement *sensor = new TiXmlElement ("Sensor");
    sensorsNode->LinkEndChild (sensor);

    /* Set sensor attributes */
    sensor->SetAttribute ("tag", iter->get_tag ().c_str ());
    sensor->SetAttribute ("online", iter->get_online ());
    sensor->SetDoubleAttribute ("x", iter->get_x_coord ());
    sensor->SetDoubleAttribute ("y", iter->get_y_coord ());
    sensor->SetAttribute ("adata", iter->get_amount_data ());
    sensor->SetAttribute ("type", iter->get_type ().c_str ());
  }

  /* Save xml to file */
  doc.SaveFile (filename.c_str ());
}
示例#6
0
/* Method TreeModel_to_XML */
void ClusterSettings::TreeModel_to_XML (const Glib::ustring& filename,
                                Glib::RefPtr<Gtk::ListStore> sensors_list)
{
  /* Get ListStore contents */
  sensors_list->foreach_iter (sigc::mem_fun (*this,
                             &ClusterSettings::on_foreach_iter));

  /* Create xml document */
  xmlpp::Document doc;

  /* Create root node */
  xmlpp::Element *root_node = doc.create_root_node ("SensorsClusterSettings");

  /* Add root comment */
  Glib::ustring message;
  message.assign ("File created by ComLibSim at [");
  message.append (filename);
  message.append ("]");
  root_node->add_child_comment (message);

  /* Create and set cluster node */
  xmlpp::Element *cluster_node = root_node->add_child ("Cluster");
  cluster_node->set_attribute ("name", m_Name);

  /* Create and set sensor elements */
  std::list<SensorSettings>::iterator iter;
  for (iter=m_Sensors.begin (); iter != m_Sensors.end (); iter++)
  {
    const SensorSettings& sensor_iter = *iter;

    /* Sensor element */
    xmlpp::Element *sensor_element = cluster_node->add_child ("Sensor");

    /* Set sensor attributes */
    sensor_element->set_attribute ("tag", iter->get_tag ());
    sensor_element->set_attribute ("online", iter->get_online_as_string ());
    Glib::ustring tmp;
    tmp = Glib::ustring::format (std::fixed, std::setprecision (6),
                                 iter->get_x ());
    sensor_element->set_attribute ("x", tmp);
    tmp = Glib::ustring::format (std::fixed, std::setprecision (6),
                                 iter->get_y ());
    sensor_element->set_attribute ("y", tmp);
    tmp = Glib::ustring::format (std::fixed, std::setprecision (0),
                                 iter->get_adata ());
    sensor_element->set_attribute ("adata", tmp);
    sensor_element->set_attribute ("type", iter->get_type ());
  }

  /* Save to xml file */
  doc.write_to_file (filename);
}
示例#7
0
Glib::ustring post_office::pull_data () {

	Glib::ustring data = "";
	
	if(connected)
	{
			
		char buffer[512];
		int bytes = 0;
			
		bytes = recv(sock, buffer, 512, MSG_DONTWAIT);
		if(bytes < 0)
		{
			if( errno != EAGAIN )
			{			
	  			this->set_last_error("Failed to receive bytes from server");
			}
			return "";
		}
		
		data.append(buffer, bytes);	
		return data;
	}
	this->set_last_error("Not connected");
	return "";
}
示例#8
0
URI URI::fromUtf8( gchar const* path ) throw (BadURIException) {
    if ( !path ) {
        throw MalformedURIException();
    }
    Glib::ustring tmp;
    for ( int i = 0; path[i]; i++ )
    {
        gint one = 0x0ff & path[i];
        if ( ('a' <= one && one <= 'z')
             || ('A' <= one && one <= 'Z')
             || ('0' <= one && one <= '9')
             || one == '_'
             || one == '-'
             || one == '!'
             || one == '.'
             || one == '~'
             || one == '\''
             || one == '('
             || one == ')'
             || one == '*'
            ) {
            tmp += (gunichar)one;
        } else {
            gchar scratch[4];
            g_snprintf( scratch, 4, "%c%02X", '%', one );
            tmp.append( scratch );
        }
    }
    const gchar *uri = tmp.data();
    URI result(uri);
    return result;
}
示例#9
0
Glib::ustring FormatToUTF8::checkUTF8charBYchar(const std::string& s)
{
	std::string::const_iterator it ;
	Glib::ustring res = "" ;
	for (it=s.begin(); it!=s.end(); it++)
	{
		gchar c = *it ;
		gboolean valid = g_utf8_validate(&c, 1*sizeof(gchar), NULL) ;
    	if (valid){
    		res.append(Glib::ustring(1, c)) ;
    	}
		else {
			res.append(TAG_INVALID_UTF8_CHAR) ;
		}
	}
	return res ;
}
示例#10
0
/*  --------------------------------------------------------  */
bool Terminal::set_interface(Glib::ustring deviceName, int speed)
{
    try {
        if(this->interface != NULL)
            return false;
        else
            this->interface = new InOutInterface(&deviceName, speed);

        /* Sets the callback for to read from the serial port */
        if(this->interface != NULL && this->interface->is_open())
            this->interface->set_read_callback(sigc::mem_fun(*this, &Terminal::update_read));

        return this->interface->is_open();
    } 
    catch(std::exception &ex) {
        Glib::ustring err = "Unable to open device because: \"";
        err.append(ex.what()); err.append("\"");
        Log::LogWarn(LEVEL_LOG_WARNING, err.c_str(), __FILE__, __LINE__);
    }

    return false;
}
示例#11
0
static void sp_image_image_edit(GtkMenuItem *menuitem, SPAnchor *anchor)
{
    SPObject* obj = anchor;
    Inkscape::XML::Node *ir = obj->getRepr();
    const gchar *href = ir->attribute("xlink:href");

    GError* errThing = 0;
    Glib::ustring cmdline = getImageEditorName();
    Glib::ustring name;
    Glib::ustring fullname;
    
#ifdef WIN32
    // g_spawn_command_line_sync parsing is done according to Unix shell rules,
    // not Windows command interpreter rules. Thus we need to enclose the
    // executable path with sigle quotes.
    int index = cmdline.find(".exe");
    if ( index < 0 ) index = cmdline.find(".bat");
    if ( index < 0 ) index = cmdline.find(".com");
    if ( index >= 0 ) {
        Glib::ustring editorBin = cmdline.substr(0, index + 4).c_str();
        Glib::ustring args = cmdline.substr(index + 4, cmdline.length()).c_str();
        editorBin.insert(0, "'");
        editorBin.append("'");
        cmdline = editorBin;
        cmdline.append(args);
    } else {
        // Enclose the whole command line if no executable path can be extracted.
        cmdline.insert(0, "'");
        cmdline.append("'");
    }
#endif

    if (strncmp (href,"file:",5) == 0) {
    // URI to filename conversion
      name = g_filename_from_uri(href, NULL, NULL);
    } else {
      name.append(href);
    }


    if (Glib::path_is_absolute(name)) {
        fullname = name;
    } else if (SP_ACTIVE_DOCUMENT->getBase()) {
        fullname = Glib::build_filename(SP_ACTIVE_DOCUMENT->getBase(), name);
    } else {
        fullname = Glib::build_filename(Glib::get_current_dir(), name);
    }


    cmdline.append(" '");
    cmdline.append(fullname.c_str());
    cmdline.append("'");

    //g_warning("##Command line: %s\n", cmdline.c_str());

    g_spawn_command_line_async(cmdline.c_str(),
                  &errThing); 

    if ( errThing ) {
        g_warning("Problem launching editor (%d). %s", errThing->code, errThing->message);
        SPDesktop *desktop = (SPDesktop*)gtk_object_get_data(GTK_OBJECT(menuitem), "desktop");
        desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, errThing->message);
        g_error_free(errThing);
        errThing = 0;
    }
}
示例#12
0
void JsCompressorFrame::evt_executeBtn_clicked() {
	if (this->m_root_path_entry.get_text_length() <= 0) {
		return;
	}
	this->init_logfile();
	this->iter_filelist();
	Glib::ustring targetFiles;
	size_t length = files.size();
	for (size_t k = 0; k < length; k++) {
		targetFiles.append(";");
		targetFiles.append(files[k]);
	}

	Glib::ustring cmd;
	if (OS_IS_WINDOWS) {
		cmd.append("\"");
		cmd.append(tinyms::FileUtils::__APSPATH__);
		cmd.append("/jre6/bin/javaw.exe\" -jar compressorhelper.jar");
	} else {
		cmd.append("java -jar compressorhelper.jar");
	}
	cmd.append(" -selected-folder ");
	cmd.append(this->m_root_path_entry.get_text());
	cmd.append(" -files ");
	cmd.append(targetFiles.substr(1, targetFiles.size()));
	cmd.append(" -type ");
	if (this->m_jsOrCssChkbox.get_active()) {
		cmd.append("css");
	} else {
		cmd.append("js");
	}
	cmd.append(" -aio ");
	cmd.append("true");
	system(cmd.c_str());
	std::cout << cmd << std::endl;

	this->read_logfile();

}