bool CMake::LoadList(const wxString& type, CMake::HelpMap& list, LoadNotifier* notifier, int limit) { const wxString command = GetPath().GetFullPath(); // Get list wxArrayString names; const wxString cmdList = command + " --help-" + type + "-list"; ProcUtils::SafeExecuteCommand(cmdList, names); // Remove version if (!names.IsEmpty()) names.RemoveAt(0); const int notifyCount = (names.GetCount() / limit) + 1; int loaded = 0; // Foreach names for (wxArrayString::const_iterator it = names.begin(), ite = names.end(); it != ite; ++it) { if ( notifier && notifier->RequestStop() ) { // Someone called 'wxThread::Delete' return false; } // Trim name wxString name = *it; name.Trim().Trim(false); // Export help wxArrayString desc; const wxString cmdItem = command + " --help-" + type + " \"" + name + "\""; ProcUtils::SafeExecuteCommand(cmdItem, desc); // Skip empty results if (desc.IsEmpty()) continue; // Remove first line (cmake version) if (desc.Item(0).Matches("*cmake version*")) desc.RemoveAt(0); // Store help page list[name] = CreateHtml(desc); // One more loaded loaded++; // Add 1% if (notifier && loaded == notifyCount) { notifier->Inc(1); loaded = 0; } } return true; }
bool HtmlPdfEngine::CreatePdf(const HtmlParam& param) { if (!CreateHtml(param)) { return false; } QString header_opt_("--header-html"); QString header_html("./htmltemplate/header.html"); QString footer_opt("--footer-html"); QString footer_html("./htmltemplate/footer.html"); // QString footer_line("--no-footer-line"); QString page_offset("--page-offset"); QString page_offset_value("-1"); QString orientation_opt("-O"); QString landscape("LandScape"); QString cover("cover"); QString cover_html("./htmltemplate/cover.html"); QString input("./htmltemplate/temp.html"); QString output("./test.pdf.tmp"); if (!QFile::exists(header_html) || !QFile::exists(footer_html) || !QFile::exists(cover_html) || !QFile::exists(input)) { return false; } QStringList arguments; arguments << header_opt_ << header_html << footer_opt << footer_html << page_offset << page_offset_value << orientation_opt << landscape << cover << cover_html << input << output; QProcess proc; int state = proc.execute("./wkhtmltopdf-amd64", arguments); QTime t; t.start(); while(t.elapsed() < 2000) { QCoreApplication::processEvents(); usleep(100); } if (state == -1 || state == -2) { return false; } // delete temp.html QFile::remove(input); // make sure that the .pdf file is already generated. if (!QFile::exists(output)) { return false; } else { std::string temp = param.version_.report_name_; if (QFile::exists(QString(temp.c_str()))) { QFile::remove(QString(temp.c_str())); } if (!QFile::rename(output, QString(temp.c_str()))) { QFile::remove(output); return false; } } return true; }