Ejemplo 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;
}
Ejemplo n.º 2
0
	void show_dialog() const
	{
		Gtk::MessageDialog* dialog = new Gtk::MessageDialog(
			m_simple_desc,
			false,
			Gtk::MESSAGE_ERROR,
			Gtk::BUTTONS_NONE,
			false);

		Gtk::Window* parent = NULL;
		Gtk::Widget* toplevel_widget = m_widget->get_toplevel();
		if(gtk_widget_is_toplevel(toplevel_widget->gobj()))
			parent = dynamic_cast<Gtk::Window*>(toplevel_widget);

		g_assert(parent != NULL);
		dialog->set_transient_for(*parent);

		dialog->add_button(_("_Close"), Gtk::RESPONSE_CLOSE);

		dialog->set_secondary_text(m_detail_desc, true);
		dialog->signal_response().connect(
			sigc::hide(
				sigc::bind(
					sigc::ptr_fun(dispose_dialog),
					dialog)));
		dialog->show();
	}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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 ();
  }
}
Ejemplo n.º 5
0
	void show_dialog() const
	{
		Gtk::MessageDialog* dialog = new Gtk::MessageDialog(
			m_simple_desc,
			false,
			Gtk::MESSAGE_ERROR,
			Gtk::BUTTONS_NONE,
			false);

		dialog->add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);

		dialog->set_secondary_text(m_detail_desc, true);
		dialog->signal_response().connect(
			sigc::hide(
				sigc::bind(
					sigc::ptr_fun(dispose_dialog),
					dialog)));
		dialog->show();
	}
Ejemplo n.º 6
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);
    }
}
Ejemplo n.º 7
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;
}