Project* ProjectManager::create_new_project(const QString& templatefile, const QString& projectName) { if (project_exists(projectName)) { info().critical(tr("Project %1 already exists!").arg(projectName)); return 0; } QString newrootdir = config().get_property("Project", "directory", "/directory/unknown/").toString() + "/" + projectName; m_projectDirs.append(newrootdir); Project* newProject = new Project(projectName); if (newProject->create(0, 0) < 0) { delete newProject; info().critical(tr("Unable to create new Project %1").arg(projectName)); return 0; } if (newProject->save_from_template_to_project_file(templatefile, projectName) < 0) { return 0; } emit projectsListChanged(); return newProject; }
void ProjectManager::start(const QString & basepath, const QString & projectname) { config().set_property("Project", "directory", basepath); if (project_exists(projectname)) { load_project(projectname); } }
int ProjectManager::load_project(const QString& projectName) { PENTER; if( ! project_exists(projectName) ) { PERROR("project %s doesn't exist!", projectName.toAscii().data()); return -1; } Project* newProject = new Project(projectName); if (!newProject) return -1; set_current_project(newProject); int err; if ((err = m_currentProject->load()) < 0) { switch (err) { case Project::PROJECT_FILE_VERSION_MISMATCH: { emit projectFileVersionMismatch(m_currentProject->get_root_dir(), m_currentProject->get_title()); break; } default: { emit projectLoadFailed(m_currentProject->get_title(), m_currentProject->get_error_string()); } } info().critical(tr("Unable to load Project %1").arg(projectName)); set_current_project(0); return -1; } else { m_currentProject->connect_to_audio_device(); } return 1; }
Project* ProjectManager::create_new_project(int numSheets, int numTracks, const QString& projectName) { PENTER; if (project_exists(projectName)) { info().critical(tr("Project %1 already exists!").arg(projectName)); return 0; } QString newrootdir = config().get_property("Project", "directory", "/directory/unknown/").toString() + "/" + projectName; m_projectDirs.append(newrootdir); Project* newProject = new Project(projectName); if (newProject->create(numSheets, numTracks) < 0) { delete newProject; info().critical(tr("Unable to create new Project %1").arg(projectName)); return 0; } emit projectsListChanged(); return newProject; }
void mechon_mamre_action_page (HtmlWriter2& htmlwriter) { htmlwriter.heading_open (3); htmlwriter.text_add (_("Hebrew import from Mechon Mamre")); htmlwriter.heading_close (); vector <ustring> messages; bool keep_going = true; // Locate the downloaded file. ustring ct005zipfilename = gw_build_filename (g_get_home_dir (), "ct005.zip"); messages.push_back (_("Looking for file ") + ct005zipfilename); if (!g_file_test (ct005zipfilename.c_str(), G_FILE_TEST_IS_REGULAR)) { ct005zipfilename.clear(); } if (ct005zipfilename.empty()) { ct005zipfilename = gw_build_filename (g_get_home_dir (), "Desktop", "ct005.zip"); messages.push_back (_("Looking for file ") + ct005zipfilename); if (!g_file_test (ct005zipfilename.c_str(), G_FILE_TEST_IS_REGULAR)) { ct005zipfilename.clear(); } } if (ct005zipfilename.empty()) { ct005zipfilename = gw_build_filename (g_get_home_dir (), "Downloads", "ct005.zip"); messages.push_back (_("Looking for file ") + ct005zipfilename); if (!g_file_test (ct005zipfilename.c_str(), G_FILE_TEST_IS_REGULAR)) { ct005zipfilename.clear(); } } if (ct005zipfilename.empty()) { messages.push_back (_("Can't find Hebrew input file")); keep_going = false; } if (keep_going) { messages.push_back (_("Using file ") + ct005zipfilename); } // Unpack the zipped file. ustring directory; if (keep_going) { directory = gw_build_filename (Directories->get_temp (), "uncompress"); unix_rmdir (directory); gw_mkdir_with_parents (directory); if (!uncompress (ct005zipfilename, directory)) { messages.push_back (_("Could not unpack the file")); keep_going = false; } messages.push_back (_("Unpacking into folder ") + directory); } // Show the readme file. if (keep_going) { ustring readmefile = gw_build_filename (directory, "readme.txt"); ReadText rt (readmefile, true, true); ustring line; for (unsigned int i = 0; i < rt.lines.size(); i++) { if (rt.lines[i].empty()) { if (!line.empty()) { messages.push_back (line); line.clear(); } } else { line.append (rt.lines[i] + " "); } } messages.push_back (line); } // Look for the directory where all the html files reside. if (keep_going) { directory = gw_build_filename (directory, "c", "ct"); if (!g_file_test (directory.c_str(), G_FILE_TEST_IS_DIR)) { messages.push_back (_("Can't find data in directory ") + directory); } messages.push_back (_("Looking for data in directory ") + directory); } // Get a list of the html files that have the data. vector <ustring> files; if (keep_going) { ReadFiles rf (directory, "c", ".htm"); for (unsigned int i = 0; i < rf.files.size(); i++) { ustring filename = gw_build_filename (directory, rf.files[i]); // Check on a few characteristics. if (mechon_mamre_copyright(filename)) { unsigned int digitcount = digit_count_in_string(rf.files[i]); if ((digitcount == 3) || (digitcount == 4)) { files.push_back(filename); } } } } // Create a new Bible into which to import the data. ustring bible = _("Hebrew Mechon Mamre"); if (keep_going) { if (project_exists (bible)) { messages.push_back (_("A Bible already exists by this name: ") + bible); keep_going = false; } else { project_create_restore (bible, ""); messages.push_back (_("Creating a new Bible called \"") + bible + "\""); // Make a couple of settings. extern Settings * settings; ProjectConfiguration * projectconfig = settings->projectconfig (bible); projectconfig->versification_set ("Original"); projectconfig->editable_set (false); projectconfig->right_to_left_set (true); projectconfig->spelling_check_set (false); } } // Store all the chapters 0 in each book. if (keep_going) { vector <unsigned int> books = books_type_to_ids(btOldTestament); ProgressWindow progresswindow (_("Creating books"), false); progresswindow.set_iterate (0, 1, books.size()); for (unsigned int bk = 0; bk < books.size(); bk++) { progresswindow.iterate (); vector <ustring> usfm; usfm.push_back ("\\id " + books_id_to_paratext (books[bk])); CategorizeChapterVerse ccv (usfm); project_store_chapter (bible, books[bk], ccv); } } // Store all the chapters. if (keep_going) { ProgressWindow progresswindow (_("Importing chapters"), false); progresswindow.set_iterate (0, 1, files.size()); for (unsigned int i = 0; i < files.size(); i++) { progresswindow.iterate (); unsigned int book = 0; unsigned int chapter = 0; mechon_mamre_extract_book_chapter (files[i], book, chapter); vector <ustring> contents = mechon_mamre_extract_contents (files[i], chapter); CategorizeChapterVerse ccv (contents); project_store_chapter (bible, book, ccv); messages.push_back (_("Importing ") + books_id_to_localname (book) + " " + convert_to_string (chapter) + _(" from file ") + files[i]); } } // Write accumulated messages. htmlwriter.heading_open (3); if (keep_going) { htmlwriter.text_add (_("Success! Bible was created: ") + bible); } else { htmlwriter.text_add (_("Error!")); } htmlwriter.heading_close (); if (keep_going) { htmlwriter.paragraph_open (); htmlwriter.text_add (_("To view the Hebrew text, open the Bible in the editor. Optionally set the font for better display of the Hebrew text. A donation made to Mechon Mamre will support their work.")); htmlwriter.paragraph_close (); } for (unsigned int i = 0; i < messages.size(); i++) { htmlwriter.paragraph_open (); htmlwriter.text_add (messages[i]); htmlwriter.paragraph_close (); } // Write OK. htmlwriter.paragraph_open (); htmlwriter.hyperlink_add ("ok", _("Ok")); htmlwriter.paragraph_close (); }
void PrintReferencesDialog::on_button_add(const ustring & project) // Adds a new project to the gui. { // Get list of all projects. vector < ustring > projects = projects_get_all(); // Only add the project if it exists. if (!project.empty()) { if (!project_exists(project)) { return; } } // All the widgets we're going to insert. GtkWidget *hbox5; SelectProjectGui *selectprojectgui; GtkWidget *button_additional_project; GtkWidget *alignment1; GtkWidget *hbox6; GtkWidget *image1; GtkWidget *label17; // Build GUI. hbox5 = gtk_hbox_new(FALSE, 4); gtk_widget_show(hbox5); gtk_box_pack_start(GTK_BOX(vbox1), hbox5, TRUE, TRUE, 0); selectprojectgui = new SelectProjectGui(0); selectprojectgui->build(hbox5, "", project); button_additional_project = gtk_button_new(); gtk_widget_show(button_additional_project); gtk_box_pack_start(GTK_BOX(hbox5), button_additional_project, FALSE, FALSE, 0); alignment1 = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_widget_show(alignment1); gtk_container_add(GTK_CONTAINER(button_additional_project), alignment1); hbox6 = gtk_hbox_new(FALSE, 2); gtk_widget_show(hbox6); gtk_container_add(GTK_CONTAINER(alignment1), hbox6); image1 = gtk_image_new_from_stock("gtk-remove", GTK_ICON_SIZE_BUTTON); gtk_widget_show(image1); gtk_box_pack_start(GTK_BOX(hbox6), image1, FALSE, FALSE, 0); label17 = gtk_label_new_with_mnemonic(_("Remove")); gtk_widget_show(label17); gtk_box_pack_start(GTK_BOX(hbox6), label17, FALSE, FALSE, 0); g_signal_connect((gpointer) button_additional_project, "clicked", G_CALLBACK(on_button_additional_project_clicked), gpointer(this)); gtk_box_reorder_child(GTK_BOX(vbox1), hbox5, hboxes.size() + 7); // Store the relevant widgets. hboxes.push_back(hbox5); selectprojectguis.push_back(selectprojectgui); buttons.push_back(button_additional_project); // Reorder the accelerators on the remove buttons. rewrite_button_labels(); }