Beispiel #1
0
void BZSpriteButton::_onClick()
{
	_Assert(_bEnabled);
	_setAnimateState(BS_Idle);
	_Debug("button %s clicked", this->getModName().c_str());
	_pLayer->onEvent(new CAEventCommand(this, "onClick"));
}
Beispiel #2
0
VaApi::VaApi() {
	init = true;
	auto xdpy = QX11Info::display();
	VADisplay display = m_display = vaGetDisplayGLX(xdpy);
	if (!check(display ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNIMPLEMENTED, "Cannot create VADisplay."))
		return;
	int major, minor;
	if (!check(vaInitialize(m_display, &major, &minor), "Cannot initialize VA-API."))
		return;
	auto size = vaMaxNumProfiles(display);
	m_profiles.resize(size);
	if (!check(vaQueryConfigProfiles(display, m_profiles.data(), &size), "No available profiles."))
		return;
	m_profiles.resize(size);

	for (auto profile : m_profiles) {
		int size = vaMaxNumEntrypoints(display);
        QVector<VAEntrypoint> entries(size);
		if (!isSuccess(vaQueryConfigEntrypoints(display, profile, entries.data(), &size)))
			continue;
		entries.resize(size);
		m_entries.insert(profile, entries);
	}

	initCodecs();
#ifdef USE_VAVPP
	initFilters();
#endif
	_Debug("VA-API is initialized.");
	ok = true;
}
Beispiel #3
0
void BZSpriteButton::onTouched(CAEventTouch* pEvent) 
{
	if (!_bEnabled)
		return;

	GUARD_FUNCTION();

	switch (pEvent->state())
	{
	case kTouchStateGrabbed:
		_Debug("button %s touch grabbed", this->getModName().c_str());
		if (_animateState == BS_Idle || _animateState == BS_Animated)
		{
			_Debug("button %s press", this->getModName().c_str());
			_touchState |= TS_Down;
			_setAnimateState(BS_Animating);
			setState(ButtonPose_Pressed, true);
			CASpriteModelPose* ppose = this->getCurrentPose();
			if (ppose->name() != ButtonPose_Pressed)
			{
				_onPressedAnimationFinished();
			}
		}
		else if (_animateState == BS_Animating)
		{
			//do nothing
		}
		break;
	case kTouchStateUngrabbed:
		_Debug("button %s touch ungrabbed", this->getModName().c_str());
		if (_animateState == BS_Idle)
		{
		}
		else if (_animateState == BS_Animating)
		{
			_Debug("button %s touch up flag", this->getModName().c_str());
			_touchState |= TS_Up;
		}
		else if (_animateState == BS_Animated)
		{
			_Debug("button %s touch end, onclick", this->getModName().c_str());
			if (_bEnabled) _onClick();
		}
		break;
	}
}
Beispiel #4
0
void BZSpriteButton::onTouchLeave(CAEventTouch* pEvent) 
{
	if (!_bEnabled)
		return;

	_Debug("button %s touch leave", this->getModName().c_str());
	_setAnimateState(BS_Idle);
}
Beispiel #5
0
void BZSpriteButton::_setAnimateState(EAnimateState s)
{
	GUARD_FUNCTION();
	_animateState = s;
	if (BS_Idle == s)
	{
		_touchState = TS_None;
	}
	_Debug("button %s -> %d", this->getModName().c_str(), s);
}
Beispiel #6
0
void AppX11::setScreensaverDisabled(bool disabled) {
	if (d->inhibit == disabled)
		return;
	if (disabled) {
		if (!d->iface && !d->xss) {
			_Debug("Initialize screensaver functions.");
			_Debug("Try to connect 'org.gnome.SessionManager'.");
			d->iface = new QDBusInterface("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
			if (!(d->gnome = d->iface->isValid())) {
				_Debug("Failed to connect 'org.gnome.SessionManager'. Fallback to 'org.freedesktop.ScreenSaver'.");
				delete d->iface;
				d->iface = new QDBusInterface("org.freedesktop.ScreenSaver", "/ScreenSaver", "org.freedesktop.ScreenSaver");
				if (!d->iface->isValid()) {
					_Debug("Failed to connect 'org.freedesktop.ScreenSaver'. Fallback to XResetScreenSaver().");
					delete d->iface;
					d->iface = nullptr;
					d->xss = true;
				}
			}
		}
		if (d->iface) {
			if (d->gnome)
				d->reply = d->iface->call("Inhibit", "CMPlayer", 0u, "Running player", 4u | 8u);
			else
				d->reply = d->iface->call("Inhibit", "CMPlayer", "Running player");
			if (!d->reply.isValid()) {
				_Error("DBus '%%' error: %%", d->iface->interface(), d->reply.error().message());
				_Error("Fallback to XResetScreenSaver().");
				delete d->iface;
				d->iface = nullptr;
				d->xss = true;
			} else
				_Debug("Disable screensaver with '%%'.", d->iface->interface());
		}
		if (d->xss) {
			_Debug("Disable screensaver with XResetScreenSaver().");
			d->ss_timer.start();
		}
	} else {
		if (d->iface) {
			auto response = d->iface->call(d->gnome ? "Uninhibit" : "UnInhibit", d->reply.value());
			if (response.type() == QDBusMessage::ErrorMessage)
				_Error("DBus '%%' error: [%%] %%", d->iface->interface(), response.errorName(), response.errorMessage());
			else
				_Debug("Enable screensaver with '%%'.", d->iface->interface());
		} else if (d->xss) {
			_Debug("Enable screensaver with XResetScreenSaver().");
			d->ss_timer.stop();
		}
	}
	d->inhibit = disabled;
}
Beispiel #7
0
PlayEngine::~PlayEngine()
{
    d->initialized = false;
    mpv_terminate_destroy(d->handle);
    delete d->chapterInfo;
    delete d->audio;
    delete d->video;
    delete d->filter;
    delete d;
    _Debug("Finalized");
}
Beispiel #8
0
void BZSpriteButton::_onPressedAnimationFinished()
{
	if (!_bEnabled)
		return;

	_Debug("button %s animated", this->getModName().c_str());
	_setAnimateState(BS_Animated);
	if ((_touchState & TS_Down) && (_touchState & TS_Up))
	{
		_onClick();
	}
}
Beispiel #9
0
static bool tryUnity() {
    static bool init = false;
    static bool good = false;
    if (!init) {
        init = true;
        _Debug("DE is Unity. Fallback to AppIndicator instead of QSytemTrayIcon.");
        QLibrary gtk(u"gtk-x11-2.0"_q, 0), ai(u"libappindicator"_q, 1);
        if (!gtk.load() || !ai.load())
            return false;
        auto lib = &gtk;
#define DEC_FUNC(name) if (!(name = (f_##name)lib->resolve(#name))) return false;
        DEC_FUNC(gtk_menu_new)
        DEC_FUNC(gtk_menu_item_new_with_label)
        DEC_FUNC(gtk_menu_shell_append)
        DEC_FUNC(gtk_widget_show)
        lib = &ai;
        DEC_FUNC(app_indicator_new)
        DEC_FUNC(app_indicator_set_menu)
        DEC_FUNC(app_indicator_set_status)
#undef DEC_FUNC
        good = true;
    }
    return good;
}
Beispiel #10
0
App::App(int &argc, char **argv)
: QApplication(argc, argv), d(new Data(this)) {
#ifdef Q_OS_LINUX
    setlocale(LC_NUMERIC,"C");
#endif
    setOrganizationName(u"xylosper"_q);
    setOrganizationDomain(u"xylosper.net"_q);
    setApplicationName(_L(name()));
    setApplicationVersion(_L(version()));

    Record r(APP_GROUP);
    QVariant vLocale;
    r.read(vLocale, u"locale"_q);
    setLocale(Locale::fromVariant(vLocale));

    d->addOption(LineCmd::Open, u"open"_q,
                 tr("Open given %1 for file path or URL."), u"mrl"_q);
    d->addOption(LineCmd::Wake, u"wake"_q,
                 tr("Bring the application window in front."));
    d->addOption(LineCmd::Action, u"action"_q,
                 tr("Exectute %1 action or open %1 menu."), u"id"_q);
    d->addOption(LineCmd::LogLevel, u"log-level"_q,
                 tr("Maximum verbosity for log. %1 should be one of nexts:")
                 % "\n    "_a % Log::options().join(u", "_q), u"lv"_q);
    d->addOption(LineCmd::OpenGLDebug, u"opengl-debug"_q,
                 tr("Turn on OpenGL debug logger."));
    d->addOption(LineCmd::Debug, u"debug"_q,
                 tr("Turn on options for debugging."));
    d->getCommandParser(&d->cmdParser)->process(arguments());
    d->getCommandParser(&d->msgParser);
    d->execute(&d->cmdParser);

#if defined(Q_OS_MAC) && defined(CMPLAYER_RELEASE)
    static const auto path = QApplication::applicationDirPath().toLocal8Bit();
    _Debug("Set $LIBQUVI_SCRIPTSDIR=\"%%\"", path);
    if (setenv("LIBQUVI_SCRIPTSDIR", path.data(), 1) < 0)
        _Error("Cannot set $LIBQUVI_SCRIPTSDIR. "
               "Some streaming functions won't work.");
#endif

    setQuitOnLastWindowClosed(false);
#ifndef Q_OS_MAC
    setWindowIcon(defaultIcon());
#endif

    auto makeStyle = [&]() {
        auto name = r.value(u"style"_q, styleName()).toString();
        if (style()->objectName().compare(name, QCI) == 0)
            return;
        if (!d->styleNames.contains(name, QCI))
            return;
        setStyle(QStyleFactory::create(name));
    };
    d->styleNames = [this] () {
        auto names = QStyleFactory::keys();
        const auto defaultName = style()->objectName();
        for (auto it = ++names.begin(); it != names.end(); ++it) {
            if (defaultName.compare(*it, QCI) == 0) {
                const auto name = *it;
                names.erase(it);
                names.prepend(name);
                break;
            }
        }
        return names;
    }();
    makeStyle();
    connect(&d->connection, &LocalConnection::messageReceived,
             this, &App::handleMessage);
    const auto map = r.value(u"open_folders"_q).toMap();
    QMap<QString, QString> folders;
    for (auto it = map.begin(); it != map.end(); ++it)
        folders.insert(it.key(), it->toString());
    set_open_folders(folders);
}
Beispiel #11
0
bool AppX11::shutdown() {
	_Debug("Try KDE session manger to shutdown.");
	QDBusInterface kde("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface", QDBusConnection::sessionBus());
	auto response = kde.call("logout", 0, 2, 2);
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("KDE session manager does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to Gnome session manager.");
	QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", QDBusConnection::sessionBus());
	response = gnome.call("RequestShutdown");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("Gnome session manager does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to gnome-power-cmd.sh.");
	if (QProcess::startDetached("gnome-power-cmd.sh shutdown") || QProcess::startDetached("gnome-power-cmd shutdown"))
		return true;
	_Debug("gnome-power-cmd.sh does not work.");
	_Debug("Fallback to HAL.");
	QDBusInterface hal("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
	response = hal.call("Shutdown");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("HAL does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Fallback to ConsoleKit.");
	QDBusInterface consoleKit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
	response = consoleKit.call("Stop");
	if (response.type() != QDBusMessage::ErrorMessage)
		return true;
	_Debug("ConsoleKit does not work: [%%] %%", response.errorName(), response.errorMessage());
	_Debug("Sorry, there's no way to shutdown.");
	return false;
}
Beispiel #12
0
PlayEngine::PlayEngine()
: d(new Data(this)) {
    Q_ASSERT(d->confDir.isValid());

    _Debug("Create audio/video plugins");
    d->audio = new AudioController(this);
    d->video = new VideoOutput(this);
    d->filter = new VideoFilter;

    d->chapterInfo = new ChapterInfoObject(this, this);
    d->updateMediaName();

    _Debug("Make registrations and connections");

    connect(d->video, &VideoOutput::formatChanged,
            this, &PlayEngine::updateVideoFormat);
    connect(d->video, &VideoOutput::droppedFramesChanged,
            this, &PlayEngine::droppedFramesChanged);

    d->handle = mpv_create();
    auto verbose = qgetenv("CMPLAYER_MPV_VERBOSE").toLower().trimmed();
    const QVector<QByteArray> lvs = {"no", "fatal", "error", "warn", "info",
                                     "status", "v", "debug", "trace"};
    if (lvs.indexOf(verbose) < lvs.indexOf("info"))
        verbose = "info";
    mpv_request_log_messages(d->handle, verbose.constData());

    d->observe();
    connect(this, &PlayEngine::beginChanged, this, &PlayEngine::endChanged);
    connect(this, &PlayEngine::durationChanged, this, &PlayEngine::endChanged);
    connect(this, &PlayEngine::videoStreamsChanged, this, [=] () {
        if (_Change(d->hasVideo, !d->streams[StreamVideo].tracks.isEmpty()))
            emit hasVideoChanged();
        d->videoInfo.setTracks(d->streams[StreamVideo].tracks);
    });
    connect(this, &PlayEngine::audioStreamsChanged, this, [=] ()
        { d->audioInfo.setTracks(d->streams[StreamAudio].tracks); });
    connect(this, &PlayEngine::subtitleStreamsChanged, this, [=] ()
        { d->subInfo.setTracks(d->streams[StreamSubtitle].tracks); });
    connect(this, &PlayEngine::currentVideoStreamChanged, this, [=] (int id)
        { d->videoInfo.setTrack(d->streams[StreamVideo].tracks.value(id)); });
    connect(this, &PlayEngine::currentAudioStreamChanged, this, [=] (int id)
        { d->audioInfo.setTrack(d->streams[StreamAudio].tracks.value(id)); });
    connect(this, &PlayEngine::currentSubtitleStreamChanged, this, [=] ()
        { d->subInfo.setTracks(d->streams[StreamSubtitle].tracks); });
    auto checkDeint = [=] () {
        auto act = Unavailable;
        if (d->filter->isInputInterlaced())
            act = d->filter->isOutputInterlaced() ? Deactivated : Activated;
        d->videoInfo.setDeinterlacer(act);
    };
    connect(d->filter, &VideoFilter::inputInterlacedChanged,
            this, checkDeint, Qt::QueuedConnection);
    connect(d->filter, &VideoFilter::outputInterlacedChanged,
            this, checkDeint, Qt::QueuedConnection);
    connect(d->audio, &AudioController::inputFormatChanged, this, [=] () {
        d->audioInfo.output()->setFormat(d->audio->inputFormat());
    }, Qt::QueuedConnection);
    connect(d->audio, &AudioController::outputFormatChanged, this, [=] () {
        d->audioInfo.renderer()->setFormat(d->audio->outputFormat());
    }, Qt::QueuedConnection);
    connect(d->audio, &AudioController::samplerateChanged, this, [=] (int sr) {
        d->audioInfo.renderer()->setSampleRate(sr, true);
    }, Qt::QueuedConnection);
    connect(d->audio, &AudioController::gainChanged,
            &d->audioInfo, &AudioInfoObject::setNormalizer);
    auto setOption = [this] (const char *name, const char *data) {
        const auto err = mpv_set_option_string(d->handle, name, data);
        d->fatal(err, "Couldn't set option %%=%%.", name, data);
    };
    setOption("fs", "no");
    setOption("input-cursor", "yes");
    setOption("softvol", "yes");
    setOption("softvol-max", "1000.0");
    setOption("sub-auto", "no");
    setOption("osd-level", "0");
    setOption("quiet", "yes");
    setOption("input-terminal", "no");
    setOption("ad-lavc-downmix", "no");
    setOption("title", "\"\"");
    setOption("vo", d->vo().constData());
    setOption("fixed-vo", "yes");

    auto overrides = qgetenv("CMPLAYER_MPV_OPTIONS").trimmed();
    if (!overrides.isEmpty()) {
        const auto opts = QString::fromLocal8Bit(overrides);
        const auto args = opts.split(QRegEx(uR"([\s\t]+)"_q),
                                     QString::SkipEmptyParts);
        for (int i=0; i<args.size(); ++i) {
            if (!args[i].startsWith("--"_a)) {
                _Error("Cannot parse option %%.", args[i]);
                continue;
            }
            const auto arg = args[i].midRef(2);
            const int index = arg.indexOf('='_q);
            if (index < 0) {
                if (arg.startsWith("no-"_a))
                    setOption(arg.mid(3).toLatin1(), "no");
                else
                    setOption(arg.toLatin1(), "yes");
            } else {
                const auto key = arg.left(index).toLatin1();
                const auto value = arg.mid(index+1).toLatin1();
                setOption(key, value);
            }
        }
    }
    d->fatal(mpv_initialize(d->handle), "Couldn't initialize mpv.");
    _Debug("Initialized");
    d->initialized = true;
}
Beispiel #13
0
App::App(int &argc, char **argv)
: QApplication(argc, argv), d(new Data(this)) {
#ifdef Q_OS_LINUX
	setlocale(LC_NUMERIC,"C");
#endif
	setOrganizationName("xylosper");
	setOrganizationDomain("xylosper.net");
	setApplicationName(Info::name());
	setApplicationVersion(Info::version());
	setLocale(Record(APP_GROUP).value("locale", QLocale::system()).toLocale());

	d->addOption(LineCmd::Open, "open", tr("Open given %1 for file path or URL."), "mrl");
	d->addOption(LineCmd::Wake, QStringList() << "wake", tr("Bring the application window in front."));
	d->addOption(LineCmd::Action, "action", tr("Exectute %1 action or open %1 menu."), "id");
	d->addOption(LineCmd::LogLevel, "log-level", tr("Maximum verbosity for log. %1 should be one of nexts:")
				 % "\n    " % Log::options().join(", "), "lv");
	d->addOption(LineCmd::OpenGLDebug, "opengl-debug", tr("Turn on OpenGL debug logger."));
	d->addOption(LineCmd::Debug, "debug", tr("Turn on options for debugging."));
	d->getCommandParser(&d->cmdParser)->process(arguments());
	d->getCommandParser(&d->msgParser);
	d->execute(&d->cmdParser);

#if defined(Q_OS_MAC) && defined(CMPLAYER_RELEASE)
	static const QByteArray path = QApplication::applicationDirPath().toLocal8Bit();
	_Debug("Set $LIBQUVI_SCRIPTSDIR=\"%%\"", QApplication::applicationDirPath());
	if (setenv("LIBQUVI_SCRIPTSDIR", path.data(), 1) < 0)
		_Error("Cannot set $LIBQUVI_SCRIPTSDIR. Some streaming functions won't work.");
#endif

	setQuitOnLastWindowClosed(false);
#ifndef Q_OS_MAC
	setWindowIcon(defaultIcon());
#endif
	auto makeStyleNameList = [this] () {
		auto names = QStyleFactory::keys();
		const auto defaultName = style()->objectName();
		for (auto it = ++names.begin(); it != names.end(); ++it) {
			if (defaultName.compare(*it, Qt::CaseInsensitive) == 0) {
				const auto name = *it;
				names.erase(it);
				names.prepend(name);
				break;
			}
		}
		return names;
	};
	auto makeStyle = [this]() {
		Record r(APP_GROUP);
		auto name = r.value("style", styleName()).toString();
		if (style()->objectName().compare(name, Qt::CaseInsensitive) == 0)
			return;
		if (!d->styleNames.contains(name, Qt::CaseInsensitive))
			return;
		setStyle(QStyleFactory::create(name));
	};
	d->styleNames = makeStyleNameList();
	makeStyle();
	connect(&d->connection, &LocalConnection::messageReceived, [this] (const QString &message) {
		d->msgParser.parse(message.split("[:sep:]")); d->execute(&d->msgParser);
	});
}