bool PLS::_write(const Entries &list) { Writer *writer = ioCtrl.rawPtr< Writer >(); writer->write(QString("[playlist]\r\nNumberOfEntries=" + QString::number(list.size()) + "\r\n").toUtf8()); for (int i = 0; i < list.size(); i++) { const Playlist::Entry &entry = list[i]; QString idx = QString::number(i+1); QString url = entry.url; const bool isFile = url.startsWith("file://"); if (isFile) url.remove(0, 7); #ifdef Q_OS_WIN if (isFile) url.replace("/", "\\"); #endif if (!url.isEmpty()) writer->write(QString("File" + idx + "=" + url + "\r\n").toUtf8()); if (!entry.name.isEmpty()) writer->write(QString("Title" + idx + "=" + QString(entry.name).replace('\n', '\001') + "\r\n").toUtf8()); if (entry.length >= 0) writer->write(QString("Length" + idx + "=" + QString::number(entry.length) + "\r\n").toUtf8()); if (entry.selected) writer->write(QString("QMPlay_sel" + idx + "=" + QString::number(entry.selected) + "\r\n").toUtf8()); if (entry.queue) writer->write(QString("QMPlay_queue" + idx + "=" + QString::number(entry.queue) + "\r\n").toUtf8()); if (entry.GID) writer->write(QString("QMPlay_GID" + idx + "=" + QString::number(entry.GID) + "\r\n").toUtf8()); if (entry.parent) writer->write(QString("QMPlay_parent" + idx + "=" + QString::number(entry.parent) + "\r\n").toUtf8()); } return true; }
void CalendarCell::update(const dbo::ptr<UserAccount>& user, const WDate& date) { date_ = date; user_ = user; clear(); dbo::Session& session = PlannerApplication::plannerApplication()->session; dbo::Transaction transaction(session); WString day; day += boost::lexical_cast<std::string>(date.day()); if (date.day() == 1) day += " " + WDate::longMonthName(date.month()); WText* header = new WText(day); header->setStyleClass("cell-header"); addWidget(header); typedef dbo::collection< dbo::ptr<Entry> > Entries; Entries entries = user->entriesInRange(date, date.addDays(1)); const unsigned maxEntries = 4; unsigned counter = 0; for (Entries::const_iterator i = entries.begin(); i != entries.end(); ++i, ++counter) { if (counter == maxEntries) { WText* extra = new WText(tr("calendar.cell.extra") .arg((int)(entries.size() - maxEntries))); extra->setStyleClass("cell-extra"); addWidget(extra); extra->clicked().preventPropagation(); extra->clicked().connect(this, &CalendarCell::showAllEntriesDialog); break; } WString format = EntryDialog::timeFormat; addWidget(new WText((*i)->start.toString(format) + "-" + (*i)->stop.toString(format) + ": " + (*i)->summary)); } transaction.commit(); }
inline children launch_pipeline(const Entries &entries) { BOOST_ASSERT(entries.size() >= 2); children cs; detail::file_handle fhinvalid; boost::scoped_array<detail::pipe> pipes(new detail::pipe[entries.size() - 1]); #if defined(BOOST_POSIX_API) { typename Entries::size_type i = 0; const typename Entries::value_type::context_type &ctx = entries[i].context; detail::info_map infoin, infoout; if (ctx.stdin_behavior.get_type() != stream_behavior::close) { detail::stream_info si = detail::stream_info(ctx.stdin_behavior, false); infoin.insert(detail::info_map::value_type(STDIN_FILENO, si)); } BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); detail::stream_info si2(close_stream(), true); si2.type_ = detail::stream_info::use_handle; si2.handle_ = pipes[i].wend().release(); infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si2)); if (ctx.stderr_behavior.get_type() != stream_behavior::close) { detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); } detail::posix_setup s; s.work_directory = ctx.work_directory; pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); detail::file_handle fhstdin; if (ctx.stdin_behavior.get_type() == stream_behavior::capture) { fhstdin = detail::posix_info_locate_pipe(infoin, STDIN_FILENO, false); BOOST_ASSERT(fhstdin.valid()); } cs.push_back(child(pid, fhstdin, fhinvalid, fhinvalid)); } for (typename Entries::size_type i = 1; i < entries.size() - 1; ++i) { const typename Entries::value_type::context_type &ctx = entries[i].context; detail::info_map infoin, infoout; BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); detail::stream_info si1(close_stream(), false); si1.type_ = detail::stream_info::use_handle; si1.handle_ = pipes[i - 1].rend().release(); infoin.insert(detail::info_map::value_type(STDIN_FILENO, si1)); BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); detail::stream_info si2(close_stream(), true); si2.type_ = detail::stream_info::use_handle; si2.handle_ = pipes[i].wend().release(); infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si2)); if (ctx.stderr_behavior.get_type() != stream_behavior::close) { detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); } detail::posix_setup s; s.work_directory = ctx.work_directory; pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); cs.push_back(child(pid, fhinvalid, fhinvalid, fhinvalid)); } { typename Entries::size_type i = entries.size() - 1; const typename Entries::value_type::context_type &ctx = entries[i].context; detail::info_map infoin, infoout; BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); detail::stream_info si1(close_stream(), false); si1.type_ = detail::stream_info::use_handle; si1.handle_ = pipes[i - 1].rend().release(); infoin.insert(detail::info_map::value_type(STDIN_FILENO, si1)); if (ctx.stdout_behavior.get_type() != stream_behavior::close) { detail::stream_info si = detail::stream_info(ctx.stdout_behavior, true); infoout.insert(detail::info_map::value_type(STDOUT_FILENO, si)); } if (ctx.stderr_behavior.get_type() != stream_behavior::close) { detail::stream_info si = detail::stream_info(ctx.stderr_behavior, true); infoout.insert(detail::info_map::value_type(STDERR_FILENO, si)); } detail::posix_setup s; s.work_directory = ctx.work_directory; pid_t pid = detail::posix_start(entries[i].executable, entries[i].arguments, ctx.environment, infoin, infoout, s); detail::file_handle fhstdout, fhstderr; if (ctx.stdout_behavior.get_type() == stream_behavior::capture) { fhstdout = detail::posix_info_locate_pipe(infoout, STDOUT_FILENO, true); BOOST_ASSERT(fhstdout.valid()); } if (ctx.stderr_behavior.get_type() == stream_behavior::capture) { fhstderr = detail::posix_info_locate_pipe(infoout, STDERR_FILENO, true); BOOST_ASSERT(fhstderr.valid()); } cs.push_back(child(pid, fhinvalid, fhstdout, fhstderr)); } #elif defined(BOOST_WINDOWS_API) STARTUPINFOA si; detail::win32_setup s; s.startupinfo = &si; { typename Entries::size_type i = 0; const typename Entries::value_type::context_type &ctx = entries[i].context; detail::stream_info sii = detail::stream_info(ctx.stdin_behavior, false); detail::file_handle fhstdin; if (sii.type_ == detail::stream_info::use_pipe) fhstdin = sii.pipe_->wend(); BOOST_ASSERT(ctx.stdout_behavior.get_type() == stream_behavior::close); detail::stream_info sio(close_stream(), true); sio.type_ = detail::stream_info::use_handle; sio.handle_ = pipes[i].wend().release(); detail::stream_info sie(ctx.stderr_behavior, true); s.work_directory = ctx.work_directory; ::ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); if (!::CloseHandle(pi.hThread)) boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); cs.push_back(child(pi.dwProcessId, fhstdin, fhinvalid, fhinvalid, detail::file_handle(pi.hProcess))); } for (typename Entries::size_type i = 1; i < entries.size() - 1; ++i) { const typename Entries::value_type::context_type &ctx = entries[i].context; BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); detail::stream_info sii(close_stream(), false); sii.type_ = detail::stream_info::use_handle; sii.handle_ = pipes[i - 1].rend().release(); detail::stream_info sio(close_stream(), true); sio.type_ = detail::stream_info::use_handle; sio.handle_ = pipes[i].wend().release(); detail::stream_info sie(ctx.stderr_behavior, true); s.work_directory = ctx.work_directory; ::ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); if (!::CloseHandle(pi.hThread)) boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); cs.push_back(child(pi.dwProcessId, fhinvalid, fhinvalid, fhinvalid, detail::file_handle(pi.hProcess))); } { typename Entries::size_type i = entries.size() - 1; const typename Entries::value_type::context_type &ctx = entries[i].context; BOOST_ASSERT(ctx.stdin_behavior.get_type() == stream_behavior::close); detail::stream_info sii(close_stream(), false); sii.type_ = detail::stream_info::use_handle; sii.handle_ = pipes[i - 1].rend().release(); detail::file_handle fhstdout, fhstderr; detail::stream_info sio(ctx.stdout_behavior, true); if (sio.type_ == detail::stream_info::use_pipe) fhstdout = sio.pipe_->rend(); detail::stream_info sie(ctx.stderr_behavior, true); if (sie.type_ == detail::stream_info::use_pipe) fhstderr = sie.pipe_->rend(); s.work_directory = ctx.work_directory; ::ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi = detail::win32_start(entries[i].executable, entries[i].arguments, ctx.environment, sii, sio, sie, s); if (!::CloseHandle(pi.hThread)) boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_pipeline: CloseHandle failed")); cs.push_back(child(pi.dwProcessId, fhinvalid, fhstdout, fhstderr, detail::file_handle(pi.hProcess))); } #endif return cs; }
Playlist::Entries PLS::_read() { Reader *reader = ioCtrl.rawPtr< Reader >(); Entries list; QString playlistPath = filePath(reader->getUrl()); if (playlistPath.startsWith("file://")) playlistPath.remove(0, 7); else playlistPath.clear(); const QList< QByteArray > playlistLines = readLines(); for (int i = 0; i < playlistLines.count(); ++i) { const QByteArray &line = playlistLines[i]; if (line.isEmpty()) continue; int idx = line.indexOf('='); if (idx < 0) continue; int number_idx = -1; for (int i = 0; i < line.length(); ++i) { if (line[i] == '=') break; if (line[i] >= '0' && line[i] <= '9') { number_idx = i; break; } } if (number_idx == -1) continue; QByteArray key = line.left(number_idx); QByteArray value = line.mid(idx+1); int entry_idx = line.mid(number_idx, idx - number_idx).toInt() - 1; prepareList(&list, entry_idx); if (entry_idx < 0 || entry_idx > list.size() - 1) continue; if (key == "File") list[entry_idx].url = Url(value, playlistPath); else if (key == "Title") list[entry_idx].name = value.replace('\001', '\n'); else if (key == "Length") list[entry_idx].length = value.toInt(); else if (key == "QMPlay_sel") list[entry_idx].selected = value.toInt(); else if (key == "QMPlay_queue") list[entry_idx].queue = value.toInt(); else if (key == "QMPlay_GID") list[entry_idx].GID = value.toInt(); else if (key == "QMPlay_parent") list[entry_idx].parent = value.toInt(); } return list; }