예제 #1
0
int checkStringOffset(Glib::ustring str, int toffset)
{
	//-- Empty string
	if (str.empty() || StringOps(str).trim().empty())
		return -1 ;
	//-- Before text
	if (toffset <= 0)
		return 0 ;
	//-- After text
	else if (toffset >= (str.length()-1) )
		return 1 ;
	else
	{
		const Glib::ustring& tmpBefore = str.substr(0, toffset) ;
		const Glib::ustring& tmpAfter = str.substr(toffset, str.length()-1) ;
		StringOps tmpB(tmpBefore) ;
		StringOps tmpAft(tmpAfter) ;
		//-- Before is only spaces, it's before text :)
		if (tmpB.trim(" \n").empty())
			return 0 ;
		//-- After is only spaces, it's after text :)
		else if (tmpAft.trim(" \n").empty())
			return 1 ;
		//-- Otherwise it's middle :)
		else
			return 2 ;
	}
}
예제 #2
0
/*
 * Ellipse text if longer than maxlen, "50% start text + ... + ~50% end text"
 * Text should be > length 8 or just return the original text
 */
Glib::ustring gr_ellipsize_text(Glib::ustring const &src, size_t maxlen)
{
    if (src.length() > maxlen && maxlen > 8) {
        size_t p1 = (size_t) maxlen / 2;
        size_t p2 = (size_t) src.length() - (maxlen - p1 - 1);
        return src.substr(0, p1) + "…" + src.substr(p2);
    }
    return src;
}
예제 #3
0
void
ManglerAudio::playText(Glib::ustring text) {/*{{{*/
    if (!text.length() || !Mangler::config["NotificationTextToSpeech"].toBool()) {
        return;
    }
#ifdef HAVE_ESPEAK
    espeak_SetSynthCallback(espeak_synth_cb);
    ManglerAudio *tts = new ManglerAudio(AUDIO_NOTIFY, mangler->espeakRate, 1, 0, 0, false);
    if (espeak_Synth(text.c_str(), text.length() + 1, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, tts) != EE_OK) {
        tts->finish();
        fprintf(stderr, "espeak: synth error\n");
        return;
    }
#endif
}/*}}}*/
예제 #4
0
void Document::renameFromKey ()
{
	if (getFileName().empty () || getKey().empty ())
		return;

	Glib::RefPtr<Gio::File> oldfile = Gio::File::create_for_uri(getFileName());

	Glib::ustring shortname = oldfile->query_info()->get_display_name();
	DEBUG ("Shortname = %1", shortname);
	Glib::RefPtr<Gio::File> parentdir = oldfile->get_parent();

	Glib::ustring::size_type pos = shortname.rfind (".");
	Glib::ustring extension = "";
	if (pos != Glib::ustring::npos)
		extension = shortname.substr (pos, shortname.length() - 1);

	Glib::ustring newfilename = getKey() + extension;
	DEBUG ("Newfilename = %1", newfilename);

	Glib::RefPtr<Gio::File> newfile = parentdir->get_child(newfilename);

	try {
		oldfile->move(newfile);
		setFileName (newfile->get_uri ());
	} catch (Gio::Error &ex) {
		Utility::exceptionDialog (&ex,
			String::ucompose (_("Moving '%1' to '%2'"),
				oldfile->get_uri (),
				newfile->get_uri ())
			);
	}
}
예제 #5
0
void Messages::message(char *msg)
{
    Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
    Glib::ustring uMsg = msg;
    if (uMsg[uMsg.length()-1] != '\n')
        uMsg += '\n';
    buffer->insert (buffer->end(), uMsg);
}
예제 #6
0
Glib::ustring PortConfig::select_port(Glib::ustring p)
{
        if (p.length() > 0)
        {
                cmbtPort.set_active_text(p);
                return p;
        }
        return port;
}
예제 #7
0
 static Glib::ustring fixup_suffix(const Glib::ustring& uri)
 {
    // Add .fmp extension automatically if not provided.
    size_t len = uri.length();
    if (len >= 4 && (uri.substr(len - 4) != ".fmp"))
       return uri + ".fmp";
    else
       return uri;
 }
예제 #8
0
bool exist_file_or_dir(const Glib::ustring& filename)
{
  if(!filename.length())
    return false;

  Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(Glib::filename_from_utf8(filename));

  return file && file->query_exists();
}
예제 #9
0
equation* mainWindow::createEqFromStr(Glib::ustring str)
{
	Gtk::MessageDialog tempDialog(*this, "Error!");
	unsigned int equalPos = commandLine->get_text().find("=");
	
	//check for = sign else give a error
	if(equalPos > 2000000000)
	{
		tempDialog.set_secondary_text("No \"=\" found");
		tempDialog.run();
		return 0;
	}else{
		//Now substring the str form equalPos
		Glib::ustring leftSide = str.substr(0, equalPos);
		
		//now find the function variable
		unsigned int firstBrace = leftSide.find("(");
		//if this is zero, no function name is given.
		if(firstBrace == 0)
		{
			tempDialog.set_secondary_text("No function name is given");
			tempDialog.run();
			return 0;
		}else{
			//if ( is not found error
			if(firstBrace > 2000000000)
			{
				tempDialog.set_secondary_text("Missing \"(\" in function name");
				tempDialog.run();
				return 0;
			}
			
			
			Glib::ustring afterBrace = leftSide.substr(firstBrace);
			if(afterBrace.length() != 3)
			{
				tempDialog.set_secondary_text("Syntax error in variable name");
				tempDialog.run();
				return 0;
			}
			
			Glib::ustring variableName = afterBrace.substr(1,1);
			Glib::ustring functionName = leftSide.substr(0, firstBrace);
			
			Glib::ustring rightSide = str.substr(equalPos+1);
			
			equation *tempEq = new equation();
			tempEq->setName(functionName);
			tempEq->setEquation(rightSide);
			tempEq->setVariable(variableName);
			return tempEq;
		}
	}
}
예제 #10
0
bool hasSuffix(const Glib::ustring &str, const Glib::ustring &ext)
{
    int strLen = str.length();
    int extLen = ext.length();
    if (extLen > strLen)
        return false;
    int strpos = strLen-1;
    for (int extpos = extLen-1 ; extpos>=0 ; extpos--, strpos--)
        {
        Glib::ustring::value_type ch = str[strpos];
        if (ch != ext[extpos])
            {
            if ( ((ch & 0xff80) != 0) ||
                 static_cast<Glib::ustring::value_type>( g_ascii_tolower( static_cast<gchar>(0x07f & ch) ) ) != ext[extpos] )
                {
                return false;
                }
            }
        }
    return true;
}
예제 #11
0
void AppWindow::open_new_file( Glib::ustring string_filename )
	{
	busy(true);
	char * filename = new char[string_filename.length() + 1 ];

	strcpy ( filename , string_filename.c_str() );

#ifdef DEBUG
	std::cout << "OPEN_NEW_FILE: AppWindow opens " << filename << std::endl;
#endif // DEBUG

	// this is a neat trick to use our argv reader internally, we will never drag more
	// than one URI (folder or file)!
	char *arguments[] = { "empty", filename };
	ImageManager.OpenNewSet(2, arguments);

	#ifdef DEBUG
	std::cout << "OPEN_NEW_FILE(AppWindow): Deleting the allocated memory for temporary filename.\n";
	#endif 
	delete[] filename;

	// if the buttons were not active, let's make them active if we have multiple files
	// if we don't have multiple files, let's make them inactive
	if( ImageManager.have_multiple_files() )
		{ 
		Button_Next.set_sensitive(true);
		Button_Previous.set_sensitive(true);
		}
	else
		{
		Button_Next.set_sensitive(false);
		Button_Previous.set_sensitive(false);
		}

	// set the title, load the image
	set_title( "gimmage: " + ImageManager.get_current_file() );
	ImageBox.LoadImage(	ImageManager.get_current_file(),
						&scalefactor, 
						(int)h_scroller->get_page_size(),
						(int)v_scroller->get_page_size());

    // finally, set the filechooser to the right dirname
    set_filechooser_dir();

    // activate the buttons
    set_buttons_active( ImageBox.is_loaded() );
	busy(false);

	// since we now have a new image, let's make sure the save button is off!
	Button_Save.set_sensitive( false );
}
예제 #12
0
	virtual void	on_end_element (
		Glib::Markup::ParseContext& context,
		const Glib::ustring& element)
	{
		if (Glib::str_has_prefix (text_, "<![CDATA[") &&
				Glib::str_has_suffix (text_, "]]>")) {
			text_ = text_.substr (strlen ("<![CDATA["),
				text_.length () - strlen ("<![CDATA[" "]]>"));
		}

		if (element == "doi") {
			bib_.setDoi (text_);
		} else if (element == "article_title") {
			bib_.setTitle (text_);
		/* FIXME: assuming given_name precedes surname */
		} else if (element == "given_name") {
			given_name_ = text_;
		} else if (element == "surname") {
			if (!given_name_.empty()) {
				text_ = text_ + ", " + given_name_;
				given_name_ = "";
			}
			authors_.push_back (text_);
		} else if (element == "journal_title") {
			bib_.setJournal (text_);
		} else if (element == "volume") {
			bib_.setVolume (text_);
		} else if (element == "issue") {
			bib_.setIssue (text_);
		} else if (element == "first_page") {
			bib_.setPages (text_);
		} else if (element == "year") {
			bib_.setYear (text_);
		} else if (element == "volume_title") {
			bib_.addExtra ("BookTitle", text_);
		} else if (element == "body") {
			/* End of entry */
			Glib::ustring authorString;
			std::vector<Glib::ustring>::iterator it = authors_.begin ();
			for (; it != authors_.end(); ++it) {
				if (it != authors_.begin()) {
					authorString += " and ";
				}
				authorString += *it;
			}
			if (!authorString.empty())
				bib_.setAuthors (authorString);
		}
	}
예제 #13
0
bool exist_regular_file(const Glib::ustring& filename)
{
  if(!filename.length())
    return false;

  Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(Glib::filename_from_utf8(filename));

  if(!file || !file->query_exists())
  {
    return false;
  }
  if(file->query_file_type()!=Gio::FILE_TYPE_REGULAR)
    return false;
  return true;
}
void
FontSubstitution::checkFontSubstitutions(SPDocument* doc)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    int show_dlg = prefs->getInt("/options/font/substitutedlg", 0);
    if (show_dlg) {
        Glib::ustring out;
        GSList *l =  getFontReplacedItems(doc, &out);
        if (out.length() > 0) {
            show(out, l);
        }
        if (l) {
            g_slist_free(l);
            l = NULL;
        }
    }
}
예제 #15
0
inline Glib::ustring apply_filename_macros(Glib::ustring filename)
{
   //TODO: allow the  following two macros only in the game itself:
  str_replace_all_with(filename, "$(ui-menu-icon-path)", "$(exe-share)/ui/icons/48");
  str_replace_all_with(filename, "$(ui-icon-path)", "$(exe-share)/ui/icons");
  str_replace_all_with(filename, "$(exe-share)", "$(exe-prefix)/share/$(app-name)");
  str_replace_all_with(filename, "$(test-references)", "$(local-folder)/test-references");
  str_replace_all_with(filename, "$(tmp)", "$(local-folder)/temp");
  str_replace_all_with(filename, "$(local-folder)", Private::Base::local_folder);
  str_replace_all_with(filename, "$(appdata)", Private::Base::path_appdata);
  if(filename[0]=='~')
    filename  = "$(home)"+filename.substr(1, filename.length()-1);
  str_replace_all_with(filename, "$(home)", Private::Base::path_home);
  str_replace_all_with(filename, "$(exe-prefix)", Private::Base::path_exe_prefix);
  str_replace_all_with(filename, "$(exe-filename)", Private::Base::path_exe_filename);
  str_replace_all_with(filename, "$(app-name)", Private::Base::app_name);

  return filename;
}
예제 #16
0
int is_valid_filename(Glib::ustring file_name)
{
	guint max = 256 ;
	int res = 1 ;

	//> CHECK NULL
	if( file_name.compare("")==0 ||  file_name.compare(" ")==0 )
		res=-1 ;
	//> CHECK LENGTH
	else if (file_name.length() >= max)
		res=-2 ;
	//> CHECK CHAR
	bool correct = StringOps::check_string(STRING_OPS_FORBIDDEN_FILE, file_name) ;
	if (correct && res>0)
		res = 1 ;
	else if (!correct)
		res = -3 ;

	return res ;
}
예제 #17
0
Glib::ustring PluginManager::findDataFile (Glib::ustring const file)
{
	std::vector<Glib::ustring>::iterator it = pythonPaths_.begin ();
	std::vector<Glib::ustring>::iterator const end = pythonPaths_.end ();
	for (; it != end; ++it) {
		Glib::ustring filename = Glib::build_filename (*it, file);

		if (filename.substr(0,2) == Glib::ustring ("./")) {
			filename = Glib::get_current_dir () + filename.substr (1, filename.length());
		}

		Glib::RefPtr<Gio::File> uri = Gio::File::create_for_path (filename);

		DEBUG ("Trying %1", filename);

		if (uri->query_exists ())
			return filename;
	}

	return Glib::ustring ();
}
예제 #18
0
/*
 * vim: softtabstop=4 shiftwidth=4 cindent foldmethod=marker expandtab
 *
 * $LastChangedDate$
 * $Revision$
 * $LastChangedBy$
 * $URL$
 *
 * Copyright 2009-2011 Eric Connell
 *
 * This file is part of Mangler.
 *
 * Mangler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mangler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Mangler.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mangler.h"
#include "manglerrecorder.h"
#include "mangleraudio.h"
#include "manglercharset.h"

#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>

ManglerRecorder::ManglerRecorder(Glib::RefPtr<Gtk::Builder> builder) {/*{{{*/
    this->builder = builder;

    builder->get_widget("recWindow", recWindow);
    builder->get_widget("recHide", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::hide_activate_cb));

    builder->get_widget("recOpen", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::open_activate_cb));
    builder->get_widget("recClose", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::close_activate_cb));
    builder->get_widget("recSaveAs", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::saveas_activate_cb));
    builder->get_widget("recDelete", menuitem);
    menuitem->signal_activate().connect(sigc::mem_fun(this, &ManglerRecorder::delete_activate_cb));

    builder->get_widget("recPlayPause", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::playpause_clicked_cb));
    builder->get_widget("recStop", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::stop_clicked_cb));
    builder->get_widget("recRecord", recordbutton);
    recordbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerRecorder::record_toggled_cb));
    builder->get_widget("recInfo", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::info_clicked_cb));

    builder->get_widget("recOpenEntry", fileentry);
    builder->get_widget("recOpenButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::open_activate_cb));

    filedialog = new Gtk::FileChooserDialog("Open Recording", Gtk::FILE_CHOOSER_ACTION_OPEN);
    filedialog->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    filedialog->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
    Gtk::FileFilter vrf_filter;
    vrf_filter.set_name("Ventrilo Recording File (*.vrf)");
    vrf_filter.add_pattern("*.vrf");
    filedialog->add_filter(vrf_filter);
    Gtk::FileFilter all_filter;
    all_filter.set_name("All Files");
    all_filter.add_pattern("*");
    filedialog->add_filter(all_filter);

    builder->get_widget("recScrolledWindow", recScrolledWindow);
    recListModel = Gtk::ListStore::create(recRecord);
    builder->get_widget("recListTree", recListTree);
    recListTree->set_model(recListModel);
    recListTree->append_column("Time", recRecord.time);
    recListTree->append_column("Duration", recRecord.duration);
    recListTree->append_column("Status", recRecord.status);
    recListTree->append_column("Username", recRecord.username);
    recListTree->append_column("", recRecord.text);
    recListTree->signal_cursor_changed().connect(sigc::mem_fun(this, &ManglerRecorder::recListTree_cursor_changed_cb));
    recListTree->signal_row_activated().connect(sigc::mem_fun(this, &ManglerRecorder::recListTree_row_activated_cb));

    builder->get_widget("recInfoDialog", recInfoDialog);
    builder->get_widget("recInfoCancel", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::recInfoDialog_cancel_clicked_cb));
    builder->get_widget("recInfoSave", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerRecorder::recInfoDialog_save_clicked_cb));

    recdir = ManglerConfig::confdir() + "/recordings";
    DIR *testdir;
    if ((testdir = opendir(recdir.c_str()))) {
        closedir(testdir);
    } else {
        mkdir(recdir.c_str(), 0700);
    }
    filedialog->set_current_folder(recdir);

    isPlaying   = false;
    isRecording = false;

    vrfh = NULL;
    player = NULL;
}/*}}}*/
ManglerRecorder::~ManglerRecorder() {/*{{{*/
    reset(true);
    delete filedialog;
}/*}}}*/

void
ManglerRecorder::show(void) {/*{{{*/
    recWindow->present();
}/*}}}*/
void
ManglerRecorder::hide_activate_cb(void) {/*{{{*/
    recWindow->hide();
}/*}}}*/
void
ManglerRecorder::open_activate_cb(void) {/*{{{*/
    int result = filedialog->run();
    filedialog->hide();
    if (result == Gtk::RESPONSE_OK) {
        path = filedialog->get_current_folder();
        filename = filedialog->get_filename();
        set(false);
    }
}/*}}}*/
void
ManglerRecorder::close_activate_cb(void) {/*{{{*/
    reset();
}/*}}}*/
void
ManglerRecorder::saveas_activate_cb(void) {/*{{{*/
}/*}}}*/
void
ManglerRecorder::delete_activate_cb(void) {/*{{{*/
    if (!vrfh || filename.empty()) {
        return;
    }
    Gtk::MessageDialog confirm("<b>Are you sure you want to delete \"" + fileentry->get_text() + "\"?</b>",
            true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
    if (confirm.run() == Gtk::RESPONSE_YES) {
        reset();
        unlink(filename.c_str());
    }
}/*}}}*/
void
ManglerRecorder::playpause_clicked_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    isPlaying = true;
    player = Glib::Thread::create(sigc::mem_fun(*this, &ManglerRecorder::play), false);
}/*}}}*/
void
ManglerRecorder::stop_clicked_cb(void) {/*{{{*/
    player = NULL;
}/*}}}*/
void
ManglerRecorder::record_toggled_cb(void) {/*{{{*/
    if (recordbutton->get_active()) {
        path = recdir;
        filename = path + "/" + timestamp() + ".vrf";
        set(true);
    } else {
        set(false);
    }
}/*}}}*/
void
ManglerRecorder::info_clicked_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    v3_vrf_data vrfd;
    if (v3_vrf_get_info(vrfh, &vrfd) != V3_OK) {
        mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
        return;
    }
    builder->get_widget("recInfoByEntry", entry);
    entry->set_text(c_to_ustring(vrfd.username));
    builder->get_widget("recInfoComment", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.comment));
    builder->get_widget("recInfoURL", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.url));
    builder->get_widget("recInfoCopyright", textview);
    textview->get_buffer()->set_text(c_to_ustring(vrfd.copyright));
    recInfoDialog->set_icon(mangler->icons["tray_icon"]);
    recInfoDialog->present();
}/*}}}*/
void
ManglerRecorder::recListTree_cursor_changed_cb(void) {/*{{{*/
    if (!vrfh) {
        return;
    }
    builder->get_widget("recPlayPause", widget);
    widget->set_sensitive(recListTree->get_selection()->get_selected());
}/*}}}*/
void
ManglerRecorder::recListTree_row_activated_cb(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) {/*{{{*/
    if (!vrfh) {
        return;
    }
    isPlaying = false;
    player = Glib::Thread::create(sigc::mem_fun(*this, &ManglerRecorder::play), false);
}/*}}}*/
void
ManglerRecorder::set(bool isRecording) {/*{{{*/
    reset();
    if (isRecording) {
        if (v3_vrf_record_start(filename.c_str()) != V3_OK) {
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            recordbutton->set_active(false);
            return;
        }
        this->isRecording = true;
    } else {
        this->isRecording = false;
        if (!(vrfh = v3_vrf_init(filename.c_str()))) {
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            return;
        }
        v3_vrf_data vrfd;
        if (v3_vrf_get_info(vrfh, &vrfd) != V3_OK) {
            reset();
            mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
            return;
        }
        builder->get_widget("recSize", label);
        label->set_text(bytes_to_readable(vrfd.size));
        builder->get_widget("recCount", label);
        label->set_text(float_to_ustring(v3_vrf_get_count(vrfh), 0));
        builder->get_widget("recPlatform", label);
        label->set_text(c_to_ustring(vrfd.platform));
        builder->get_widget("recVersion", label);
        label->set_text(c_to_ustring(vrfd.version));
        builder->get_widget("recCodec", label);
        label->set_text(c_to_ustring(v3_get_codec(vrfd.codec, vrfd.codecformat)->name));
        totalduration = 0;
        for (uint32_t ctr = 0, cnt = v3_vrf_get_count(vrfh); ctr < cnt; ctr++) {
            if (v3_vrf_get_segment(vrfh, ctr, &vrfd) != V3_OK) {
                reset();
                mangler->errorDialog(c_to_ustring(_v3_error(NULL)));
                return;
            }
            Gtk::TreeModel::Row row = *(recListModel->append());
            row[recRecord.id]           = ctr;
            row[recRecord.time_val]     = vrfd.time;
            row[recRecord.duration_val] = vrfd.duration;
            row[recRecord.time]         = msec_to_timestamp(vrfd.time);
            row[recRecord.duration]     = float_to_ustring(vrfd.duration / 1000.0, 2);
            row[recRecord.status]       = "";
            row[recRecord.username]     = c_to_ustring(vrfd.username);
            row[recRecord.text]         = "";
            totalduration += vrfd.duration;
        }
        builder->get_widget("recDuration", label);
        label->set_text(float_to_ustring(totalduration / 60000.0, 1) + " min");
        builder->get_widget("recInfo", widget);
        widget->set_sensitive(true);
    }
    fileentry->set_text(filename.substr(path.length() + 1));
    builder->get_widget("recType", label);
    label->set_text("VRF");
    recListTree->set_sensitive(true);
    builder->get_widget("recClose", widget);
    widget->set_sensitive(true);
    builder->get_widget("recDelete", widget);
    widget->set_sensitive(true);
    builder->get_widget("recInfos", widget);
    widget->set_sensitive(true);
    recScrolledWindow->get_vadjustment()->set_value(0);
    if (recListModel->children().size()) {
        recListTree->set_cursor(recListModel->get_path(recListModel->children().begin()));
        builder->get_widget("recPlayPause", widget);
        widget->grab_focus();
    }
}/*}}}*/
void
ManglerRecorder::reset(bool destroying) {/*{{{*/
    player = (Glib::Thread*)destroying;
    isPlaying = false;
    if (isRecording) {
        v3_vrf_record_stop();
        recordbutton->set_active(false);
    }
    isRecording = false;
    if (vrfh) {
        v3_vrf_destroy(vrfh);
        vrfh = NULL;
    }
    recListModel->clear();
    if (destroying) {
        return;
    }
    for (int ctr = 0, cnt = recListTree->get_columns().size(); ctr < cnt; ctr++) {
        recListTree->get_column(ctr)->queue_resize();
    }
    recListTree->set_sensitive(false);
    fileentry->set_text("");
    builder->get_widget("recType", label);
    label->set_text("N/A");
    builder->get_widget("recSize", label);
    label->set_text("N/A");
    builder->get_widget("recCount", label);
    label->set_text("N/A");
    builder->get_widget("recDuration", label);
    label->set_text("N/A");
    builder->get_widget("recPlatform", label);
    label->set_text("N/A");
    builder->get_widget("recVersion", label);
    label->set_text("N/A");
    builder->get_widget("recCodec", label);
    label->set_text("N/A");
    builder->get_widget("recClose", widget);
    widget->set_sensitive(false);
    builder->get_widget("recDelete", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfos", widget);
    widget->set_sensitive(false);
    builder->get_widget("recPlayPause", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfo", widget);
    widget->set_sensitive(false);
    builder->get_widget("recInfoByEntry", entry);
    entry->set_text("");
    builder->get_widget("recInfoComment", textview);
    textview->get_buffer()->set_text("");
    builder->get_widget("recInfoURL", textview);
    textview->get_buffer()->set_text("");
    builder->get_widget("recInfoCopyright", textview);
    textview->get_buffer()->set_text("");
    recInfoDialog->hide();
}/*}}}*/
void
ManglerRecorder::can_record(bool isConnected) {/*{{{*/
    if (!isConnected && isRecording) {
        set(false);
    }
    recordbutton->set_sensitive(isConnected);
}/*}}}*/
void
ManglerRecorder::record(Glib::ustring username, Glib::ustring text, uint32_t index, uint32_t time, bool stopped, bool flushed) {/*{{{*/
    if (!isRecording) {
        return;
    }
    Gtk::TreeModel::Children children = recListModel->children();
    Gtk::TreeModel::Row row;
    if (!flushed && !children[index]) {
        row = *(recListModel->append());
        row[recRecord.id]           = index;
        row[recRecord.time_val]     = time;
        row[recRecord.duration_val] = 0;
        row[recRecord.diff_val]     = 0;
        row[recRecord.time]         = msec_to_timestamp(time);
        row[recRecord.duration]     = float_to_ustring(0, 2);
        row[recRecord.status]       = "Rec";
        row[recRecord.username]     = username;
        row[recRecord.text]         = (text.length()) ? text : "";
        builder->get_widget("recCount", label);
        label->set_text(float_to_ustring(children.size(), 0));
        recListTree->set_cursor(recListModel->get_path(row));
    }
    if (flushed) {
        for (Gtk::TreeModel::iterator iter = children.begin(); iter != children.end(); iter++) {
            (*iter)[recRecord.status] = "*";
        }
        return;
    }
    row = children[index];
    if (stopped) {
        row[recRecord.status] = "*";
    } else {
        row[recRecord.duration_val] = time - row[recRecord.time_val];
    }
    if (stopped || row[recRecord.diff_val] + 100 < row[recRecord.duration_val]) {
        row[recRecord.diff_val] = time - row[recRecord.time_val];
        row[recRecord.duration] = float_to_ustring(row[recRecord.duration_val] / 1000.0, 2);
    }
}/*}}}*/
예제 #19
0
    /*
     * Set window properties that are not settable in builder
     */
    settingsWindow->set_keep_above(true);

    settingsWindow->signal_show().connect(sigc::mem_fun(this, &ManglerSettings::settingsWindow_show_cb));
    settingsWindow->signal_hide().connect(sigc::mem_fun(this, &ManglerSettings::settingsWindow_hide_cb));

    builder->get_widget("settingsCancelButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerSettings::settingsCancelButton_clicked_cb));

    builder->get_widget("settingsApplyButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerSettings::settingsApplyButton_clicked_cb));

    builder->get_widget("settingsOkButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerSettings::settingsOkButton_clicked_cb));

    builder->get_widget("settingsEnablePTTKeyCheckButton", checkbutton);
    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerSettings::settingsEnablePTTKeyCheckButton_toggled_cb));

    builder->get_widget("settingsPTTKeyButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerSettings::settingsPTTKeyButton_clicked_cb));

    builder->get_widget("settingsEnablePTTMouseCheckButton", checkbutton);
    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerSettings::settingsEnablePTTMouseCheckButton_toggled_cb));

    builder->get_widget("settingsPTTMouseButton", button);
    button->signal_clicked().connect(sigc::mem_fun(this, &ManglerSettings::settingsPTTMouseButton_clicked_cb));

    builder->get_widget("settingsEnableAudioIntegrationCheckButton", checkbutton);
    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerSettings::settingsEnableAudioIntegrationCheckButton_toggled_cb));
    builder->get_widget("settingsAudioIntegrationComboBox", audioPlayerComboBox);
    audioPlayerTreeModel = Gtk::ListStore::create(audioPlayerColumns);
    audioPlayerComboBox->set_model(audioPlayerTreeModel);
    // create a "none" row
    Gtk::TreeModel::Row audioPlayerNoneRow = *(audioPlayerTreeModel->append());
    audioPlayerNoneRow[audioPlayerColumns.id] = MusicClient_None;
    audioPlayerNoneRow[audioPlayerColumns.name] = "None";
#ifdef HAVE_LIBMPDCLIENT
    // add MPD row
    Gtk::TreeModel::Row audioPlayerMPDRow = *(audioPlayerTreeModel->append());
    audioPlayerMPDRow[audioPlayerColumns.id] = MusicClient_MPD;
    audioPlayerMPDRow[audioPlayerColumns.name] = "MPD";
#endif
#ifdef HAVE_DBUS
    // add DBUS client rows
    // rhythmbox
    Gtk::TreeModel::Row audioPlayerRBRow = *(audioPlayerTreeModel->append());
    audioPlayerRBRow[audioPlayerColumns.id] = MusicClient_Rhythmbox;
    audioPlayerRBRow[audioPlayerColumns.name] = "Rhythmbox";
    // amarok
    Gtk::TreeModel::Row audioPlayerAmarokRow = *(audioPlayerTreeModel->append());
    audioPlayerAmarokRow[audioPlayerColumns.id] = MusicClient_Amarok;
    audioPlayerAmarokRow[audioPlayerColumns.name] = "Amarok";
#endif
    audioPlayerComboBox->pack_start(audioPlayerColumns.name);
    audioPlayerComboBox->set_active(audioPlayerNoneRow);

    builder->get_widget("settingsEnableVoiceActivationCheckButton", checkbutton);
    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerSettings::settingsEnableVoiceActivationCheckButton_toggled_cb));

#ifdef HAVE_XOSD
    builder->get_widget("settingsOSD", vbox);
    vbox->set_sensitive(true);
    builder->get_widget("settingsEnableOnScreenDisplayCheckButton", checkbutton);
    checkbutton->signal_toggled().connect(sigc::mem_fun(this, &ManglerSettings::settingsEnableOnScreenDisplayCheckButton_toggled_cb));
    builder->get_widget("settingsOSDverticalPos", osdPosition);
    osdPositionModel = Gtk::ListStore::create(osdPositionColumns);
    osdPosition->set_model(osdPositionModel);
    osdPosition->pack_start(osdPositionColumns.name);
    Gtk::TreeModel::Row posrow;
    posrow = *osdPositionModel->append();
    posrow[osdPositionColumns.id] = XOSD_top;    posrow[osdPositionColumns.name] = "Top";
    posrow = *osdPositionModel->append();
    posrow[osdPositionColumns.id] = XOSD_middle; posrow[osdPositionColumns.name] = "Middle";
    posrow = *osdPositionModel->append();
    posrow[osdPositionColumns.id] = XOSD_bottom; posrow[osdPositionColumns.name] = "Bottom";

    builder->get_widget("settingsOSDhorizontalPos", osdAlignment);
    osdAlignmentModel = Gtk::ListStore::create(osdAlignmentColumns);
    osdAlignment->set_model(osdAlignmentModel);
    osdAlignment->pack_start(osdAlignmentColumns.name);
    Gtk::TreeModel::Row alnrow;
    alnrow = *osdAlignmentModel->append();
    alnrow[osdAlignmentColumns.id] = XOSD_center; alnrow[osdAlignmentColumns.name] = "Center";
    alnrow = *osdAlignmentModel->append();
    alnrow[osdAlignmentColumns.id] = XOSD_left;   alnrow[osdAlignmentColumns.name] = "Left";
    alnrow = *osdAlignmentModel->append();
    alnrow[osdAlignmentColumns.id] = XOSD_right;  alnrow[osdAlignmentColumns.name] = "Right";

    builder->get_widget("settingsOSDfontsize", osdFontSize);
    builder->get_widget("settingsOSDcolor", osdColor);
#endif

    builder->get_widget("audioSubsystemComboBox", audioSubsystemComboBox);
    audioSubsystemTreeModel = Gtk::ListStore::create(audioSubsystemColumns);
    audioSubsystemComboBox->set_model(audioSubsystemTreeModel);
    audioSubsystemComboBox->pack_start(audioSubsystemColumns.name);
    audioSubsystemComboBox->signal_changed().connect(sigc::mem_fun(this, &ManglerSettings::audioSubsystemComboBox_changed_cb));

    builder->get_widget("inputDeviceComboBox", inputDeviceComboBox);
    inputDeviceTreeModel = Gtk::ListStore::create(inputColumns);
    inputDeviceComboBox->set_model(inputDeviceTreeModel);
    inputDeviceComboBox->pack_start(inputColumns.description);
    inputDeviceComboBox->signal_changed().connect(sigc::mem_fun(this, &ManglerSettings::inputDeviceComboBox_changed_cb));

    builder->get_widget("inputDeviceCustomName", inputDeviceCustomName);

    builder->get_widget("outputDeviceComboBox", outputDeviceComboBox);
    outputDeviceTreeModel = Gtk::ListStore::create(outputColumns);
    outputDeviceComboBox->set_model(outputDeviceTreeModel);
    outputDeviceComboBox->pack_start(outputColumns.description);
    outputDeviceComboBox->signal_changed().connect(sigc::mem_fun(this, &ManglerSettings::outputDeviceComboBox_changed_cb));

    builder->get_widget("outputDeviceCustomName", outputDeviceCustomName);

    builder->get_widget("notificationDeviceComboBox", notificationDeviceComboBox);
    notificationDeviceTreeModel = Gtk::ListStore::create(notificationColumns);
    notificationDeviceComboBox->set_model(notificationDeviceTreeModel);
    notificationDeviceComboBox->pack_start(notificationColumns.description);
    notificationDeviceComboBox->signal_changed().connect(sigc::mem_fun(this, &ManglerSettings::notificationDeviceComboBox_changed_cb));

    builder->get_widget("notificationDeviceCustomName", notificationDeviceCustomName);

    mouseInputDevices = getInputDeviceList();
    builder->get_widget("settingsMouseDeviceComboBox", mouseDeviceComboBox);
    mouseDeviceTreeModel = Gtk::ListStore::create(mouseColumns);
    mouseDeviceComboBox->set_model(mouseDeviceTreeModel);
    mouseDeviceComboBox->pack_start(mouseColumns.name);

    // Audio Subsystem
    audioSubsystemTreeModel->clear();
    Gtk::TreeModel::Row audioSubsystemRow;
#ifdef HAVE_PULSE
    audioSubsystemRow = *(audioSubsystemTreeModel->append());
    audioSubsystemRow[audioSubsystemColumns.id] = "pulse";
    audioSubsystemRow[audioSubsystemColumns.name] = "PulseAudio";
#endif
#ifdef HAVE_ALSA
    audioSubsystemRow = *(audioSubsystemTreeModel->append());
    audioSubsystemRow[audioSubsystemColumns.id] = "alsa";
    audioSubsystemRow[audioSubsystemColumns.name] = "ALSA";
#endif
#ifdef HAVE_OSS
    audioSubsystemRow = *(audioSubsystemTreeModel->append());
    audioSubsystemRow[audioSubsystemColumns.id] = "oss";
    audioSubsystemRow[audioSubsystemColumns.name] = "OSS";
#endif

    // Master Volume
    volumeAdjustment = new Gtk::Adjustment(79, 0, 158, 1, 10, 10);
    volumehscale = new Gtk::HScale(*volumeAdjustment);
    volumehscale->add_mark(148, Gtk::POS_LEFT, "200%");
    volumehscale->add_mark(79, Gtk::POS_LEFT, "100%");
    volumehscale->add_mark(0, Gtk::POS_LEFT, "0%");
    volumehscale->set_inverted(false);
    volumehscale->set_draw_value(false);
    builder->get_widget("masterVolumeVbox", vbox);
    vbox->pack_start(*volumehscale);
    volumehscale->show();

    // Input Gain
    gainAdjustment = new Gtk::Adjustment(79, 0, 158, 1, 10, 10);
    gainhscale = new Gtk::HScale(*gainAdjustment);
    gainhscale->add_mark(148, Gtk::POS_LEFT, "200%");
    gainhscale->add_mark(79, Gtk::POS_LEFT, "100%");
    gainhscale->add_mark(0, Gtk::POS_LEFT, "0%");
    gainhscale->set_inverted(false);
    gainhscale->set_draw_value(false);
    builder->get_widget("inputGainVbox", vbox);
    vbox->pack_start(*gainhscale);
    gainhscale->show();
}/*}}}*/
void ManglerSettings::applySettings(void) {/*{{{*/
    Gtk::TreeModel::iterator iter;
    GdkWindow *rootwin = gdk_get_default_root_window();

    // Key Push to Talk
    builder->get_widget("settingsEnablePTTKeyCheckButton", checkbutton);
    Mangler::config["PushToTalkKeyEnabled"] = checkbutton->get_active();
    builder->get_widget("settingsPTTKeyValueLabel", label);
    if (label->get_label() != PTT_KEY_GET && label->get_label() != PTT_KEY_SET) {
        Mangler::config["PushToTalkKeyValue"] = label->get_text();
    } else {
        Mangler::config["PushToTalkKeyValue"] = "";
    }
    //Mangler::config.parsePushToTalkValue(config.PushToTalkKeyValue);

    // Mouse Push to Talk
    builder->get_widget("settingsMouseDeviceComboBox", combobox);
    iter = combobox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        Mangler::config["MouseDeviceName"] = Glib::ustring( row[mouseColumns.name] );
    }
    builder->get_widget("settingsEnablePTTMouseCheckButton", checkbutton);
    Mangler::config["PushToTalkMouseEnabled"] = checkbutton->get_active();
    builder->get_widget("settingsPTTMouseValueLabel", label);
    if (label->get_label() != PTT_MOUSE_GET && label->get_label() != PTT_MOUSE_SET) {
        Glib::ustring PushToTalkMouseValue = label->get_text();
        if (PushToTalkMouseValue.length() > 6) {
            Mangler::config["PushToTalkMouseValue"] = PushToTalkMouseValue.substr(6);
        } else {
            Mangler::config["PushToTalkMouseValue"] = PushToTalkMouseValue;
        }
    } else {
        Mangler::config["PushToTalkMouseValue"] = "";
    }
    XUngrabButton(GDK_WINDOW_XDISPLAY(rootwin), AnyButton, AnyModifier, GDK_ROOT_WINDOW());
    XAllowEvents (GDK_WINDOW_XDISPLAY(rootwin), AsyncBoth, CurrentTime);
    /*
    if (checkbutton->get_active()) {
        XGrabButton(GDK_WINDOW_XDISPLAY(rootwin), config.PushToTalkMouseValueInt, AnyModifier, GDK_ROOT_WINDOW(), False, ButtonPressMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
    }
    */

    // Audio Player Integration
    builder->get_widget("settingsEnableAudioIntegrationCheckButton", checkbutton);
    Mangler::config["AudioIntegrationEnabled"] = checkbutton->get_active();
    iter = audioPlayerComboBox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        uint8_t id = row[audioPlayerColumns.id];
        Mangler::config["AudioIntegrationPlayer"] = id;
        if (Mangler::config["AudioIntegrationEnabled"].toBool()) {
            mangler->integration->setClient((MusicClient)id);
        } else {
            mangler->integration->setClient(MusicClient_None);
        }
    }
    mangler->integration->update(true);

    // Voice Activation
    builder->get_widget("settingsEnableVoiceActivationCheckButton", checkbutton);
    Mangler::config["VoiceActivationEnabled"] = checkbutton->get_active();
    builder->get_widget("settingsVoiceActivationSilenceDurationSpinButton", spinbutton);
    Mangler::config["VoiceActivationSilenceDuration"] = spinbutton->get_value() * 1000.0;
    builder->get_widget("settingsVoiceActivationSensitivitySpinButton", spinbutton);
    Mangler::config["VoiceActivationSensitivity"] = spinbutton->get_value_as_int();

#ifdef HAVE_XOSD
    // On-Screen Display
    builder->get_widget("settingsEnableOnScreenDisplayCheckButton", checkbutton);
    Mangler::config["OnScreenDisplayEnabled"] = checkbutton->get_active();
    if (checkbutton->get_active()) {
        Gtk::TreeModel::iterator pos_iter = osdPosition->get_active();
        if (pos_iter) {
            int vert_pos_int = (*pos_iter)[osdPositionColumns.id];
            Mangler::config["OnScreenDisplayVerticalPosition"] = vert_pos_int;
        }
        Gtk::TreeModel::iterator aln_iter = osdAlignment->get_active();
        if (aln_iter) {
            int horz_aln_int = (*aln_iter)[osdAlignmentColumns.id];
            Mangler::config["OnScreenDisplayHorizontalAlignment"] = horz_aln_int;
        }
        Mangler::config["OnScreenDisplayFontSize"] = osdFontSize->get_value();
        Gdk::Color color = osdColor->get_color();
        char colorstr[16];
        snprintf(colorstr, 15, "#%02x%02x%02x", color.get_red() / 256, color.get_green() / 256, color.get_blue() / 256);
        Mangler::config["OnScreenDisplayColor"] = colorstr;
        mangler->osd->destroyOsd();
    }
#endif

    // Audio Devices
    iter = inputDeviceComboBox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        Mangler::config["InputDeviceName"] = Glib::ustring( row[inputColumns.name] );
    }
    Mangler::config["InputDeviceCustomName"] = inputDeviceCustomName->get_text();
    iter = outputDeviceComboBox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        Mangler::config["OutputDeviceName"] = Glib::ustring( row[outputColumns.name] );
    }
    Mangler::config["OutputDeviceCustomName"] = outputDeviceCustomName->get_text();
    iter = notificationDeviceComboBox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        Mangler::config["NotificationDeviceName"] = Glib::ustring( row[notificationColumns.name] );
    }
    Mangler::config["NotificationDeviceCustomName"] = notificationDeviceCustomName->get_text();
    iter = audioSubsystemComboBox->get_active();
    if (iter) {
        Gtk::TreeModel::Row row = *iter;
        Mangler::config["AudioSubsystem"] = Glib::ustring( row[audioSubsystemColumns.id] );
    }

    // Master Volume
    Mangler::config["MasterVolumeLevel"] = volumeAdjustment->get_value();
    v3_set_volume_master(Mangler::config["MasterVolumeLevel"].toInt());
    mangler->setTooltip();

    // Input Gain
    Mangler::config["InputGainLevel"] = gainAdjustment->get_value();
    v3_set_volume_xmit(Mangler::config["InputGainLevel"].toInt());

    // Notification Sounds
    builder->get_widget("notificationLoginLogoutCheckButton", checkbutton);
    Mangler::config["NotificationLoginLogout"] = checkbutton->get_active();

    builder->get_widget("notificationChannelEnterLeaveCheckButton", checkbutton);
    Mangler::config["NotificationChannelEnterLeave"] = checkbutton->get_active();

    builder->get_widget("notificationTalkStartEndCheckButton", checkbutton);
    Mangler::config["NotificationTransmitStartStop"] = checkbutton->get_active();

    builder->get_widget("notificationTTSCheckButton", checkbutton);
    Mangler::config["NotificationTextToSpeech"] = checkbutton->get_active();

    // Debug Level
    uint32_t debuglevel = 0;
    builder->get_widget("debugStatus", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_STATUS : 0;

    builder->get_widget("debugError", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_ERROR : 0;

    builder->get_widget("debugStack", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_STACK : 0;

    builder->get_widget("debugInternalNet", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_INTERNAL : 0;

    builder->get_widget("debugPacketDump", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_PACKET : 0;

    builder->get_widget("debugPacketParse", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_PACKET_PARSE : 0;

    builder->get_widget("debugEventQueue", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_EVENT : 0;

    builder->get_widget("debugSocket", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_SOCKET : 0;

    builder->get_widget("debugNotice", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_NOTICE : 0;

    builder->get_widget("debugInfo", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_INFO : 0;

    builder->get_widget("debugMutex", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_MUTEX : 0;

    builder->get_widget("debugMemory", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_MEMORY : 0;

    builder->get_widget("debugEncryptedPacket", checkbutton);
    debuglevel |= checkbutton->get_active() ? V3_DEBUG_PACKET_ENCRYPTED : 0;

    Mangler::config["lv3_debuglevel"] = debuglevel;

    v3_debuglevel(debuglevel);
    Mangler::config.config.save();
}/*}}}*/
예제 #20
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;
    }
}
예제 #21
0
void EditNoteDialog::verifyInputData()
{
    const Glib::ustring title = entryTitle->get_text();
    const Glib::ustring desc = textDescription->get_buffer()->get_text(false);
    const Glib::ustring date = entryDate->get_text();
    const Glib::ustring time = entryTime->get_text();
    const bool isReminder = checkReminder->get_active();

    bool title_valid = false;
    bool date_valid = false;
    bool time_valid = false;

    //check title
    if (title.length() > 0)
    {
        title_valid = true;
    }

    //check date
    DateValue dateValue;
    if (dateValue.parseString(date))
    {
        date_valid = true;
    }

    //check time
    TimeValue timeValue;
    if (timeValue.parseString(time))
    {
        time_valid = true;
    }

    if (title_valid && date_valid && time_valid)
    {
        isInputDataValid = true;

        btnSave->set_sensitive(true);
        infoBar->setText(Gtk::MESSAGE_INFO, lang::getString(lang::EDIT_NOTE_INPUT_VALIDATED));

        //update note data
        noteData->setDate(dateValue);
        noteData->setTime(timeValue);
        noteData->setReminder(isReminder);
        noteData->setTitle(title);
        noteData->setDetails(desc);
    }
    else
    {
        isInputDataValid = false;

        btnSave->set_sensitive(false);

        std::string message = lang::getString(lang::EDIT_NOTE_INPUT_NOT_VALIDATED);

        if (!title_valid)
            message = lang::getString(lang::EDIT_NOTE_INPUT_CORRECT_TITLE);

        if (title_valid && !date_valid)
            message = lang::getString(lang::EDIT_NOTE_INPUT_CORRECT_DATE);

        if (title_valid && date_valid && !time_valid)
            message = lang::getString(lang::EDIT_NOTE_INPUT_CORRECT_TIME);

        infoBar->setText(Gtk::MESSAGE_ERROR, message);
    }
}
예제 #22
0
bool FileManager::OpenFiles(int argc, char **argv)
	{
#ifdef DEBUG
std::cout << "OPENFILES: OpenFiles called \n";
#endif // DEBUG

	// makes sure we're dealing with a clean slate
	filenames.clear();
	numfiles = 0;
	cwd_checked = false;
	initialised = false;
	
	/* //	if we have initialised already we're being called from the file selector and will
	//	accept new files now, let's set initialised and cwd_checked to 'false' and clear our file list
	if( initialised == true )
		{
		numfiles = 0;
		cwd_checked = false;
		initialised = false;
		} // */
		
#ifdef DEBUG
std::cout << "OPENFILES: get_current_dir_name(): " << get_current_dir_name() << std::endl;
#endif // DEBUG
		
	if( argc > 1 )
		{
		for(int i = 1; i < argc; i++)
			{
			if( stat(argv[i], &filemode) != 0 )
				{
				std::cout << GT( "OPENFILES: Stat Error! Level 1 " ) << argv[i] << std::endl;
				}
			else
				{
				Glib::ustring filename;
				
				// Resolve any ".." and double / in the filename and make the filename absolute
				if( Glib::path_is_absolute( argv[i] ) )
					filename = argv[i] ;
				else
					filename = (Glib::ustring)get_current_dir_name() + "/" + (Glib::ustring)argv[i];
				
				while( filename.find("..") != Glib::ustring::npos )
					{
					filename.erase( 
						filename.rfind( '/', filename.find("..")-2), 
						filename.find("..")+2 - filename.rfind( '/', filename.find("..")-2) );
					}
				while( filename.find("//") != Glib::ustring::npos )
					filename.erase(
						filename.find("//"), filename.find("//")+1 );
				if( filename[ filename.length()-1 ] == '/' )
					filename.erase( filename.length()-1, filename.length() );
					
					
				if(filemode.st_mode & S_IFREG )  // if the file is a regular file
					{
					if( filter_filename(filename) ) // and seems to be a supported format
						{
						#ifdef DEBUG
						std::cout << "FILEMANAGER: curent argv: " << filename << std::endl;
						std::cout << "FILEMANAGER: dirname from argv: " << Glib::path_get_dirname( filename ) << std::endl;
						std::cout << "FILEMANAGER: curent dir: " << get_current_dir_name() << std::endl;
						#endif
						  
						filenames.insert( filenames.end(), filename ); // insert into list
						numfiles++;
						}
					}
				else if(filemode.st_mode & S_IFDIR) 			// if the file is a directory
					{
					cwd_checked = true;
					if((currdir = opendir(filename.c_str())) != NULL) 	// open it
						{
						while( (dirinfo = readdir(currdir)) != NULL ) // run through it
							{
							// don't forget, we're doing some string to char* conversions here 
							// here to avoid memory errors.. Glib::ustring is nice!
							Glib::ustring currfile(filename); 				// store the directory name
							currfile += '/'; 							// add a directory dash
							currfile += dirinfo->d_name; 				// add the filename
							if(stat(currfile.c_str(), &filemode) != 0)  // check for filetype
								{
								std::cout << GT( "OPENFILES: Stat Error! Level 2 " ) << currfile << std::endl;
								}
							else
								{
								if( filemode.st_mode & S_IFREG && filter_filename(currfile) ) // as above
									{
					                filenames.insert( filenames.end(), currfile ); // insert into list
									numfiles++;
									}
								}
							}
						closedir(currdir);
						}
					}
				}
			}
		filenames.sort();
		file_iterator = filenames.begin();
		}

	// when only one file was openened, we'll scan through its directory
	// and give the user control over the files
	if ( numfiles == 1 && cwd_checked == false )
		{
			cwd_checked = true;

			Glib::ustring tempfilename = *file_iterator;
			
			// prepare the file's directory name in such a way that we can pass
			// it to OpenFiles() which operates on argc/argv	
			char *dirname = new char[ (Glib::path_get_dirname( *file_iterator )).length() + 1  ];
			strcpy( dirname, (Glib::path_get_dirname( *file_iterator )).c_str() );

			char *arguments[] = { "empty" , dirname };

			// we erase the list of filenames as otherwise we would have one file twice
			filenames.clear();
			numfiles = 0;

			// now let's open the file's directory and check its contents
			OpenFiles( 2, arguments );

			// now we have a new set of files in the list, we have to find the file that
			// the user actually wanted to open!

			std::list<Glib::ustring>::iterator end = filenames.end();
			while( file_iterator != end )
				{
				#ifdef DEBUG
				std::cout << "OPENFILES: Looking for " << tempfilename << " in " << (*file_iterator) << std::endl;
				#endif
				if( (*file_iterator).find( tempfilename ) != Glib::ustring::npos )
					{
					break; // break out of the while loop if we find the filename
					}
				file_iterator++;
				}
			// when we have reached the end while looking, let's just load the first image!
			// as that means that either we didn't recognize the filename in our search above
			// or there was only one file in the directory after all!
			if( file_iterator == end )
				file_iterator = filenames.begin();

			#ifdef DEBUG
			std::cout << "OPENFILES: Deleting temporary dirname. \n";
			#endif
			
			delete[] dirname;
		}	
		
	// everything seems to have worked out alright, let's return true
	if ( numfiles > 0 )
		{
		#ifdef DEBUG
		std::cout << "OPENFILES: We're all set to go and we have " << numfiles << " files." << std::endl; 
		#endif // DEBUG
		return true;
		}
		// we did not have sufficient arguments or we have made some mistake, return false
	else
		{
		#ifdef DEBUG
		std::cout << "OPENFILES: We have " << numfiles << " files." << std::endl;
		#endif
		return false;
		}	

	}