Exemplo n.º 1
0
View *View::create(Model *model)
{
  std::vector<std::string> dirs = Platform::getConfigPaths();
  Glib::ustring ui;
  for (std::vector<std::string>::const_iterator i = dirs.begin();
       i != dirs.end(); ++i) {
    std::string f_name = Glib::build_filename (*i, "repsnapper.ui");
    Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(f_name);
    try {
      char *ptr;
      gsize length;
      file->load_contents(ptr, length);
      ui = Glib::ustring(ptr);
      g_free(ptr);
      break;
    } catch(Gio::Error e) {
      switch(e.code()) {
      case Gio::Error::NOT_FOUND:
        continue;

      default:
        Gtk::MessageDialog dialog (_("Error reading UI description!!"), false,
                                  Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
        dialog.set_secondary_text(e.what());
        dialog.run();
        return NULL;
      }
    }
  }

  if(ui.empty()) {
    Gtk::MessageDialog dialog (_("Couldn't find UI description!"), false,
                              Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
    dialog.set_secondary_text (_("Check that repsnapper has been correctly installed."));
    dialog.run();
    return NULL;
  }

  Glib::RefPtr<Gtk::Builder> builder;
  try {
    builder = Gtk::Builder::create_from_string(ui);
  }
  catch(const Gtk::BuilderError& ex)
  {
    Gtk::MessageDialog dialog (_("Error loading UI!"), false,
                              Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
    dialog.set_secondary_text(ex.what());
    dialog.run();
    throw ex;
  }
  View *view = 0;
  builder->get_widget_derived("main_window", view);
  view->setModel (model);

  return view;
}
Exemplo n.º 2
0
Glib::ustring Document::keyReplaceDialog (
	Glib::ustring const &original,
	Glib::ustring const &replacement,
	const char *message_text)
{
	Glib::ustring message = String::ucompose (
		"<big><b>%1</b></big>\n\n%2",
		_("Key naming conflict"),
		String::ucompose (
			message_text,
			original, replacement));

	Gtk::MessageDialog dialog (message, true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE, true);
	Gtk::Button *button;

	button = dialog.add_button (_("_Ignore"), Gtk::RESPONSE_CANCEL);
	Gtk::Image *noImage = Gtk::manage (new Gtk::Image (Gtk::Stock::NO, Gtk::ICON_SIZE_BUTTON));
	button->set_image (*noImage);

	button = dialog.add_button (_("_Replace"), Gtk::RESPONSE_ACCEPT);
	Gtk::Image *yesImage = Gtk::manage (new Gtk::Image (Gtk::Stock::YES, Gtk::ICON_SIZE_BUTTON));
	button->set_image (*yesImage);
	dialog.set_default_response (Gtk::RESPONSE_ACCEPT);

	if (dialog.run () == Gtk::RESPONSE_ACCEPT)
		return replacement;
	else
		return original;
}
Exemplo n.º 3
0
void PredicateDialog::onAddPredicate() {
    SimpleTypeBox box( ("New predicate name?"), "");
    std::string name = boost::trim_copy(box.run());
    if (box.valid() and checkName(name)) {
        setSensitivePredicate(false);
        Gtk::TreeIter iter = m_model->append();
        if (iter) {
            savePreviousPredicate(mPredicateNameEntry->get_text());
            mPredicateNameEntry->set_text(name);
            Gtk::ListStore::Row row = *iter;
            row[m_viewscolumnrecord.name] = name;

            mTextViewFunction->get_buffer()->set_text("");
            mHeaderPred->set_text( "bool " + name
            + "() const {" );

            m_iter = iter;
            mTreePredicateList->set_cursor(m_model->get_path(iter));
            mPredicateName.push_back(name);
            setSensitivePredicate(true);
        }
    }
    else {
        Gtk::MessageDialog errorDial ("Name error !",
            false,
            Gtk::MESSAGE_ERROR,
            Gtk::BUTTONS_OK,
            true);
        errorDial.set_title("Error !");
        errorDial.run();
    }
}
Exemplo n.º 4
0
void MainSynthWindow::onDspEntryActivate (void)
{
    gthPatchManager *patchMgr = gthPatchManager::instance();
    string dspfile = dspEntry_.get_text();
    int pagenum = notebook_.get_current_page();

    /* noop caused by a spurious Enter */
    if (dspfile == "")
        return;
    
    if (patchMgr->newPatch(dspfile, pagenum) == false)
    {
        char *error = g_strdup_printf("Couldn't load DSP %s; syntax error, or does not exist",
            dspfile.c_str());
        
        Gtk::MessageDialog errorDialog (error, false, Gtk::MESSAGE_ERROR);
        
        errorDialog.run();

        free(error);

        return;
    }

    notebook_.hide_all();
    notebook_.pages().clear();
    populate();
    notebook_.show_all();

    notebook_.set_current_page(pagenum);
}
Exemplo n.º 5
0
// Function executed after the map has been solved
void MapWindow::on_notification_from_worker_thread()
{
	if (m_WorkerThread && worker.has_stopped())
	{
		// Show a window dialog if there is no solution
		if( !worker.get_solution_exists() )
		{
			DialogWindow.notification();
			Gtk::MessageDialog *dlg = new Gtk::MessageDialog("No solution exists.");
			dlg->run();
			delete dlg;
		}
		// Work is done.
		m_WorkerThread->join();
		m_WorkerThread = NULL;

		// Update buttons
		m_Button_Solve.set_sensitive(false);
		m_Button_File.set_sensitive(true);

		// Force the on_draw function
		m_draw.queue_draw();

		// Hide the spinner window
		DialogWindow.notification();
	}
}
Exemplo n.º 6
0
void PredicateDialog::onRenamePredicate() {
    Glib::RefPtr < Gtk::TreeView::Selection > ref = mTreePredicateList->
        get_selection();
    if (ref) {
        Gtk::TreeModel::iterator iter = ref->get_selected();
        if (iter) {
            Gtk::TreeModel::Row row = *iter;
            std::string oldName(row.get_value(m_viewscolumnrecord.name));
            savePreviousPredicate(oldName);

            SimpleTypeBox box(("Predicate new name?"), "");
            std::string name = boost::trim_copy(box.run());
            if (box.valid() and checkName(name)) {

                setSensitivePredicate(false);
                m_model->erase(iter);

                Gtk::TreeModel::Children children = m_model->children();
                m_iter = children.begin();

                iter = m_model->append();
                mPredicateNameEntry->set_text(name);
                Gtk::ListStore::Row row = *iter;
                row[m_viewscolumnrecord.name] = name;

                if (mPredicateFunction.find(oldName) !=
                        mPredicateFunction.end()) {
                    mTextViewFunction->get_buffer()->
                            set_text(mPredicateFunction[oldName]);
                    mPredicateFunction[name] = mPredicateFunction[oldName];
                    mPredicateFunction.erase(oldName);
                }

                mPredicateName.push_back(name);
                // Delete the element in the vector
                for (std::vector < std::string > ::iterator it =
                        mPredicateName.begin(); it != mPredicateName.end(); ) {
                    if ( *it == oldName ) {
                        it = mPredicateName.erase(it);
                    }
                    else {
                        ++it;
                    }
                }
                mTreePredicateList->set_cursor(m_model->get_path(iter));
                setSensitivePredicate(true);
            }
            else {
                Gtk::MessageDialog errorDial ("Name error !",
                    false,
                    Gtk::MESSAGE_ERROR,
                    Gtk::BUTTONS_OK,
                    true);
                errorDial.set_title("Error !");
                errorDial.run();
            }
        }
    }
}
Exemplo n.º 7
0
	void ShowMessage(const Glib::ustring& s, Gtk::Window* parent)
	{
		Gtk::MessageDialog* msg = new Gtk::MessageDialog(s);
		if(parent)
			msg->set_transient_for(*parent);
		msg->run();
		delete msg;
	}
Exemplo n.º 8
0
void View::alert (Gtk::MessageType t, const char *message,
		  const char *secondary)
{
  Gtk::MessageDialog dialog (*this, message, false /* markup */,
			     t, Gtk::BUTTONS_CLOSE, true);
  if (secondary)
    dialog.set_secondary_text (secondary);
  dialog.run();
}
Exemplo n.º 9
0
void LoginWindow::new_user_clicked()
{
  if (login.get_text() != "" && pass.get_text() != "" && uc->addUser(login.get_text(), pass.get_text()))
  {
    Gtk::MessageDialog *info = new Gtk::MessageDialog("Konto utworzono");
    info->set_modal(true);
    info->run();
    delete info;
  }
}
Exemplo n.º 10
0
void MainSynthWindow::onPatchLoadError (const char* failure)
{
    char *error = g_strdup_printf("Couldn't load patchfile %s; syntax error, or DSP does not exist",
        failure);
        
    Gtk::MessageDialog errorDialog (error, false, Gtk::MESSAGE_ERROR);
    
    errorDialog.run();
    free(error);
}
Exemplo n.º 11
0
void Model::SendNow(string str)
{
  if (rr_dev_fd (m_device) > 0)
    rr_dev_enqueue_cmd (m_device, RR_PRIO_HIGH, str.data(), str.size());

  else {
    Gtk::MessageDialog dialog ("Can't send command", false,
                              Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE);
    dialog.set_secondary_text ("You must first connect to a device!");
    dialog.run ();
  }
}
Exemplo n.º 12
0
    void show()
    {
      openfluid::core::UnitsCollection* TestUnitsColl = 0;

      if (!mp_SimulationBlob)
      {
        mp_Dialog->set_message("I am DummyModalWindow\n"
          "Nb of units in TestUnits class: no CoreRepository\n"
          "Nothing to do");
      }
      else
      {
        unsigned int Size = 0;

        TestUnitsColl = mp_SimulationBlob->getCoreRepository().getUnits(
            "TestUnits");

        if (TestUnitsColl)
          Size = TestUnitsColl->getList()->size();

        mp_Dialog->set_message(Glib::ustring::compose("I am DummyModalWindow\n"
          "Nb of units in TestUnits class: %1\n"
          "Clicking ok will add a Unit of class \"TestUnits\"", Size));
      }

      if (mp_Dialog->run() == Gtk::RESPONSE_OK && mp_SimulationBlob)
      {
        unsigned int NextId = 1;

        if (TestUnitsColl)
        {
          openfluid::core::UnitsList_t* TestUnits = TestUnitsColl->getList();
          if (!TestUnits->empty())
          {
            NextId = TestUnits->end().operator --()->getID() + 1;

            while (TestUnitsColl->getUnit(NextId))
              NextId++;
          }

        }

        openfluid::core::Unit U("TestUnits", NextId, 1,
            openfluid::core::InstantiationInfo::DESCRIPTOR);

        mp_SimulationBlob->getCoreRepository().addUnit(U);

        signal_ChangedOccurs().emit();
      }

      mp_Dialog->hide();
    }
Exemplo n.º 13
0
void DocumentProperties::onNewExtraField ()
{
	Gtk::Dialog dialog ("New Field", *dialog_, true, false);

	Gtk::VBox *vbox = dialog.get_vbox ();

	Gtk::HBox hbox;
	hbox.set_spacing (12);
	vbox->pack_start (hbox, true, true, 0);

	Gtk::Label label ("Field name:", false);
	hbox.pack_start (label, false, false, 0);

	Gtk::Entry entry;
	entry.set_activates_default (true);
	hbox.pack_start (entry, true, true, 0);

	dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	dialog.add_button (Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
	dialog.set_default_response (Gtk::RESPONSE_ACCEPT);

	dialog.show_all ();
	vbox->set_border_width (12);

	if (dialog.run () == Gtk::RESPONSE_ACCEPT) {

		Gtk::ListStore::iterator it = extrafieldsstore_->children().begin ();
		Gtk::ListStore::iterator const end = extrafieldsstore_->children().end ();
		bool key_isnew = true;
		for (; it != end; ++it)
			if (Utility::firstCap ((*it)[extrakeycol_]) == Utility::firstCap (entry.get_text ())) {
				key_isnew = false;
			}
		if ( key_isnew ) {
			Gtk::ListStore::iterator row = extrafieldsstore_->append ();
			(*row)[extrakeycol_] = Utility::firstCap (entry.get_text ());
			(*row)[extravalcol_] = "";
		} else {
			Glib::ustring message;
			message = String::ucompose (
			"<b><big>%1</big></b>",
			_("This key already exists.\n"));
			Gtk::MessageDialog dialog (

			message, true,
			Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);

			dialog.run ();

		}
	}
}
Exemplo n.º 14
0
void LoginWindow::ok_clicked()
{
  if (login_ok = uc->checkUser(login.get_text(), pass.get_text()))
  {
    hide();
  }
  else
  {
    Gtk::MessageDialog *info = new Gtk::MessageDialog("Błędny login lub hasło.");
    info->set_modal(true);
    info->run();
    delete info;
  }
}
Exemplo n.º 15
0
void PhotoPreview::SetSilhouette() {
	try {
		Image=Gdk::Pixbuf::create_from_file(Cfg->GetSilhouetteImage());
	} catch(...) {
		Gtk::MessageDialog *message = new Gtk::MessageDialog(_("Error reading data file: ")+Cfg->GetSilhouetteImage()+"\n",
			false,Gtk::MESSAGE_WARNING,Gtk::BUTTONS_OK,true);
		message->run();
		delete message;
		return;
	}

	Redraw();
	IsSilhouette=true;
}
Exemplo n.º 16
0
void
catch_and_return_to_GUI_thread (void)
{
  try
    {
      throw;
    }
  catch (const std::exception& e)
    {
      Gtk::MessageDialog dialog (e.what (), false, Gtk::MESSAGE_ERROR);

      dialog.set_keep_above ();
      dialog.run ();
    }
}
Exemplo n.º 17
0
void MainSynthWindow::onBrowseButton (void)
{
    gthPatchManager *patchMgr = gthPatchManager::instance();
    int pagenum = notebook_.get_current_page();
    Gtk::FileSelection fileSel("thinksynth - Load DSP");

    if (prevDir_ != "")
        fileSel.set_filename(prevDir_);

    if (fileSel.run() == Gtk::RESPONSE_OK)
    {
        dspEntry_.set_text(fileSel.get_filename());

        if (patchMgr->newPatch(fileSel.get_filename(), pagenum))
        {
            string dn = thUtil::dirname((char*)fileSel.get_filename().c_str());

            prevDir_ = dn + "/";

            string **vals = new string *[2];
            vals[0] = new string(prevDir_);
            vals[1] = NULL;

            gthPrefs *prefs = gthPrefs::instance();
            prefs->Set("dspdir", vals);

            /* load up the patch file */
            notebook_.hide_all();
            notebook_.pages().clear();
            populate();
            notebook_.show_all();
            notebook_.set_current_page(pagenum);
        }
        else
        {
            char *error = g_strdup_printf("Couldn't load DSP %s; syntax error, or does not exist",
                fileSel.get_filename().c_str());
        
            Gtk::MessageDialog errorDialog (error, false, Gtk::MESSAGE_ERROR);
        
            errorDialog.run();

            free(error);
        }
    }
}
Exemplo n.º 18
0
void mixer_window::open_quit_dialog()
{
    Gtk::MessageDialog dialog (*this, gettext("Really quit?"), false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
    dialog.add_button(gettext("No, continue running dvswitch."), Gtk::RESPONSE_CANCEL);
    dialog.add_button(gettext("Yes, exit dvswitch."), Gtk::RESPONSE_YES);
    dialog.set_default_response(Gtk::RESPONSE_CANCEL);
    dialog.set_position (Gtk::WIN_POS_CENTER_ON_PARENT);
    switch (dialog.run())
    {
	case Gtk::RESPONSE_ACCEPT:
	case Gtk::RESPONSE_YES:
	    Gtk::Main::quit();
	    break;
	default:
	    break;
    }
}
Exemplo n.º 19
0
void DocumentProperties::onPasteBibtex ()
{
	GdkAtom const selection = GDK_SELECTION_CLIPBOARD;

	Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get (selection);

	Glib::ustring clipboardtext = clipboard->wait_for_text ();

	DocumentList doclist;
	int const imported = doclist.import (clipboardtext, BibUtils::FORMAT_BIBTEX);

	DEBUG ("DocumentProperties::onPasteBibtex: Imported %1 references", imported);

	if (imported) {
		DocumentList::Container &docs = doclist.getDocs ();
		DocumentList::Container::iterator it = docs.begin ();

		/*
		 * This will lose the key from the bibtex since it's
		 * in Document not BibData
		 */
		Document doc;
		save(doc);
		doc.getBibData().mergeIn (it->getBibData());
		update (doc);
	} else {
		Glib::ustring message;
	       
		if (imported < 1) {
			message = String::ucompose (
				"<b><big>%1</big></b>",
				_("No references found on clipboard.\n"));
		} else {
			message = String::ucompose (
				"<b><big>%1</big></b>",
				_("Multiple references found on clipboard.\n"));
		}

		Gtk::MessageDialog dialog (
			message, true,
			Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);

		dialog.run ();
	}
}
Exemplo n.º 20
0
void AckFunctionDialog::onAddAck() {
    SimpleTypeBox box( ("New acknowledge function name?"), "");
    std::string name = boost::trim_copy(box.run());

    if (box.valid()) {
        if (checkName(name)) {
            setSensitiveAck(false);
            Gtk::TreeIter iter = m_model->append();
            if (iter) {
                savePreviousAck(mAckNameEntry->get_text());
                mAckNameEntry->set_text(name);
                Gtk::ListStore::Row row = *iter;
                row[m_viewscolumnrecord.name] = name;

                mHeaderAck->set_text("void " + name + "(const std::string&"\
                        "activityname,\n\t"\
                        "const ved::Activity& activity) {");

                std::string generatedFunc = "";

                mTextViewFunction->get_buffer()->set_text(generatedFunc);

                m_iter = iter;
                mTreeAckList->set_cursor(m_model->get_path(iter));
                mAckName.push_back(name);
                setSensitiveAck(true);
            }
        }
        else {
            Gtk::MessageDialog errorDial ("Name error !",
                false,
                Gtk::MESSAGE_ERROR,
                Gtk::BUTTONS_OK,
                true);
            errorDial.set_title("Error !");
            errorDial.run();
        }
    }
}
Exemplo n.º 21
0
static void connectDialog (int error)
{
    string msg;
    
    switch (error)
    {
        case gthJackAudio::ERR_NO_PLAYBACK:
            msg = "Could not find a playback target for JACK\n"
                    "(alsa_pcm or oss.)";
            break;
        case gthJackAudio::ERR_HANDLE_NULL:
            msg = "Can't connect to the JACK server because it no\n"
                      "longer seems to be running.";
            break;
        default:
            msg = "Could not (dis)connect JACK, errno = " + error;
            break;
    }

    Gtk::MessageDialog errorDialog (msg.c_str(), false, Gtk::MESSAGE_ERROR);
    errorDialog.run();
}
Exemplo n.º 22
0
 void show()
 {
     mp_Dialog->run();
     mp_Dialog->hide();
 }
Exemplo n.º 23
0
void
file_chooser::on_response (int response_id)
{
  if (Gtk::RESPONSE_ACCEPT != response_id) return;

  if (get_current_extension ().empty ())
    set_current_extension (default_extension_);

  std::string fmt;
  {                             // check whether extension is known
    std::string ext (get_current_extension ());
    bool found = false;
    Gtk::TreeModel::Children children (file_type_.get_model ()->children ());

    for (Gtk::TreeModel::Children::const_iterator it = children.begin ();
         !found && children.end () != it;
         ++it)
      {
        Gtk::TreeModel::Row r = *it;
        extension_list      l = r[column->exts];

        found = count (l.begin (), l.end (), ext);

        if (found) fmt = r[column->text];
      }

    if (!found)
      {
        Gtk::MessageDialog tbd
          (*this, _("Unsupported file format."),
           use_markup, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, modal);

        tbd.set_secondary_text
          ((format (_("The '%1%' file extension is not associated with"
                      " a supported file format.  Please select a file"
                      " format or use one of the known file extensions."))
            % ext).str ());

        if (dynamic_cast< Gtk::Window * > (this))
          get_group ()->add_window (tbd);

        tbd.run ();
        signal_response ().emission_stop ();
        response (Gtk::RESPONSE_CANCEL);
        return;
      }
  }
  if (!single_image_mode_
      && requests_single_file (get_current_name ()))
    {                           // check whether single file is okay
      if (!supports_multi_image (get_current_name ()))
        {
          Gtk::MessageDialog tbd
            (*this, (format (_("The %1% format does not support multiple"
                               " images in a single file.")) % fmt).str (),
             use_markup, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, modal);

          tbd.set_secondary_text
            ((format (_("Please save to PDF or TIFF if you want a single"
                        " file.  If you prefer the %1% image format, use"
                        " a filename such as 'Untitled-%%3i%2%'."))
              % fmt % get_current_extension ()).str ());

          if (dynamic_cast< Gtk::Window * > (this))
            get_group ()->add_window (tbd);

          tbd.run ();
          signal_response ().emission_stop ();
          response (Gtk::RESPONSE_CANCEL);
          return;
        }
    }

  if (!do_overwrite_confirmation_) return;

  format message;
  format details;

  if (requests_single_file (get_current_name ()))
    {
      if (!fs::exists (std::string (get_filename ()))) return;

      message = format (_("The name \"%1%\" already exists.\n"
                          "OK to overwrite this name using the new settings?"));
      details = format (_("The file already exists in \"%1%\"."
                          "  Replacing it will overwrite its contents."));
    }
  else
    {
      // FIXME Add meaningful checking
      // if (no_possible_matches ) return;

      message = format (_("Files matching \"%1%\" may already exist."
                          "  Do you want to replace them?"));
    //details = format (_("These files already exist in \"%1%\"."
    //                    "  Replacing them may overwrite their contents."));

      // FIXME show list of matching files in an expander with details
    }

  message % get_current_name ();
  if (0 < details.size ())
    details % get_current_folder ();

  Gtk::MessageDialog tbd (*this, message.str (), use_markup,
                          Gtk::MESSAGE_QUESTION,
                          Gtk::BUTTONS_NONE, modal);

  if (0 < details.size ())
    tbd.set_secondary_text (details.str ());
  tbd.add_button (Gtk::Stock::NO , Gtk::RESPONSE_CANCEL);
  tbd.add_button (Gtk::Stock::YES, Gtk::RESPONSE_ACCEPT);
  tbd.set_default_response (Gtk::RESPONSE_ACCEPT);

  if (dynamic_cast< Gtk::Window * > (this))
    get_group ()->add_window (tbd);

  if (Gtk::RESPONSE_ACCEPT != tbd.run ())
    {
      signal_response ().emission_stop ();
      response (Gtk::RESPONSE_CANCEL);
    }
}
Exemplo n.º 24
0
int main(int argc, char **argv)
{
  Glib::thread_init();
  // gdk_threads_init(); // locks everything at least on freebsd
  Gtk::Main tk(argc, argv);

  gchar *locale_dir;

#ifdef G_OS_WIN32
  char *inst_dir;
  inst_dir = g_win32_get_package_installation_directory_of_module (NULL);
  locale_dir = g_build_filename (inst_dir, "share", "locale", NULL);
  g_free (inst_dir);
#else
  locale_dir = g_strdup (LOCALEDIR);
#endif
  bindtextdomain (GETTEXT_PACKAGE, locale_dir);
  textdomain (GETTEXT_PACKAGE);

  //cerr << locale_dir<< endl;
  g_free(locale_dir);
  locale_dir = NULL;

  if (!gtk_gl_init_check (&argc, &argv) ||
      !gdk_gl_init_check (&argc, &argv) ) {
    std::cerr << "Failed to initialize GL\n";
    return 1;
  }

  CommandLineOptions opts (argc, argv);

  Platform::setBinaryPath (argv[0]);

  Model *model = new Model();

  try {
    std::string user_config_dir = Glib::build_filename (Glib::get_user_config_dir(), "repsnapper");
    Gio::File::create_for_path(user_config_dir)->make_directory_with_parents();
  } catch(Gio::Error e) {
    switch(e.code()) {
    case Gio::Error::EXISTS:
      // Directory has already been created.  Normal.
      break;

    default:
      Gtk::MessageDialog dialog (_("Couldn't create user config directory!"),
				 false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
      dialog.set_secondary_text(e.what());
      dialog.run();
      return 1;
    }
  }

  std::vector<std::string> user_config_bits(3);
  user_config_bits[0] = Glib::get_user_config_dir();
  user_config_bits[1] = "repsnapper";
  user_config_bits[2] = "repsnapper.conf";

  std::string user_config_file = Glib::build_filename (user_config_bits);
  Glib::RefPtr<Gio::File> conf = Gio::File::create_for_path(user_config_file);

  try {
    Glib::RefPtr<Gio::File> global = find_global_config();
    if(!global) {
      // Don't leave an empty config file behind
      conf->remove();
      Gtk::MessageDialog dialog (_("Couldn't find global configuration!"),
				 false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
      dialog.set_secondary_text (_("It is likely that repsnapper is not correctly installed."));
      dialog.run();
      return 1;
    }
    
    global->copy(conf);
  } catch(Gio::Error e) {
    switch(e.code()) {
    case Gio::Error::EXISTS:
      // The user already has a config.  This is the normal case.
      break;

    case Gio::Error::PERMISSION_DENIED:
    {
      // Fall back to global config
      Gtk::MessageDialog dialog (_("Unable to create user config"), false,
                                Gtk::MESSAGE_WARNING, Gtk::BUTTONS_CLOSE);
      dialog.set_secondary_text(e.what() + _("\nFalling back to global config. Settings will not be saved."));
      dialog.run();
      conf = find_global_config();
      if(!conf) {
        Gtk::MessageDialog dialog (_("Couldn't find global configuration!"), false,
                                  Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
        dialog.set_secondary_text (_("It is likely that repsnapper is not correctly installed."));
        dialog.run();
        return 1;
      }
      break;
    }

    default:
    {
      Gtk::MessageDialog dialog (_("Failed to locate config"), false,
				 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
      dialog.set_secondary_text(e.what());
      dialog.run();
      return 1;
    }
    }
  }

  if (opts.settings_path.size() > 0)
    model->LoadConfig(Gio::File::create_for_path(opts.settings_path));
  else {
      // TODO: Error detection
    model->LoadConfig(conf);
  }

  bool nonprintingmode = false;
  if (opts.stl_input_path.size() > 0) {
    model->Read(Gio::File::create_for_path(opts.stl_input_path));
  }

  if (opts.gcode_output_path.size() > 0) {
    nonprintingmode = true;
  }

  if (!opts.use_gui) {
      if (opts.settings_path.size() > 0)
        model->LoadConfig(Gio::File::create_for_path(opts.settings_path));

      ViewProgress vprog(new Gtk::HBox(),new Gtk::ProgressBar(),new Gtk::Label());
      vprog.set_terminal_output(true);
      model->SetViewProgress(&vprog);
      model->statusbar=NULL;
      if (opts.gcode_output_path.size() > 0) {
	model->ConvertToGCode();
        model->WriteGCode(Gio::File::create_for_path(opts.gcode_output_path));
      }
      else if (opts.svg_output_path.size() > 0) {
	model->SliceToSVG(Gio::File::create_for_path(opts.svg_output_path),
			  opts.svg_single_output);
      }
      else if (opts.binary_output_path.size() > 0) {
	model->SaveStl(Gio::File::create_for_path(opts.binary_output_path));
      }
      else cerr << _("No output file given") << endl;
    return 0;
  }

  View* mainwin = View::create(model);

  mainwin->setNonPrintingMode(nonprintingmode, opts.gcode_output_path);

  mainwin->set_icon_name("gtk-convert");
  mainwin->set_title("Repsnapper");

  for (uint i = 0; i < opts.files.size(); i++)
    model->Read(Gio::File::create_for_path(opts.files[i]));

  tk.run();

  delete mainwin;
  delete model;

  return 0;
}
Exemplo n.º 25
0
void AckFunctionDialog::onRenameAck() {
    Glib::RefPtr < Gtk::TreeView::Selection > ref = mTreeAckList->
        get_selection();
    if (ref) {
        Gtk::TreeModel::iterator iter = ref->get_selected();
        if (iter) {
            Gtk::TreeModel::Row row = *iter;
            std::string oldName(row.get_value(m_viewscolumnrecord.name));
            savePreviousAck(oldName);

            SimpleTypeBox box(("Acknowledge function new name?"), "");
            std::string name = boost::trim_copy(box.run());
            if (box.valid()) {
                if (checkName(name)) {
                    setSensitiveAck(false);
                    m_model->erase(iter);

                    Gtk::TreeModel::Children children = m_model->children();
                    m_iter = children.begin();

                    iter = m_model->append();
                    mAckNameEntry->set_text(name);
                    Gtk::ListStore::Row row = *iter;
                    row[m_viewscolumnrecord.name] = name;

                    if (mAckFunction.find(oldName) != mAckFunction.end()) {
                        mTextViewFunction->get_buffer()->
                                set_text(mAckFunction[oldName]);
                        mAckFunction[name] = mAckFunction[oldName];
                        mAckFunction.erase(oldName);
                    }

                    mAckName.push_back(name);

                    mRenameList.push_back(std::make_pair(oldName, name));

                    mHeaderAck->set_text("void " + name + "(const std::string&"\
                        "activityname,\n\t"\
                        "const ved::Activity& activity) {");
                    // Delete the element in the vector
                    for (std::vector < std::string > ::iterator it =
                            mAckName.begin(); it != mAckName.end(); ) {
                        if ( *it == oldName ) {
                            it = mAckName.erase(it);
                        }
                        else {
                            ++it;
                        }
                    }
                    mTreeAckList->set_cursor(m_model->get_path(iter));
                    setSensitiveAck(true);
                }
                else {
                    Gtk::MessageDialog errorDial ("Name error !",
                        false,
                        Gtk::MESSAGE_ERROR,
                        Gtk::BUTTONS_OK,
                        true);
                    errorDial.set_title("Error !");
                    errorDial.run();
                }
            }
        }
    }
}