Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>feat/libmpv-backend
parent
a629f68164
commit
f9aeaa2575
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Kaffeine libmpv part
|
||||
* Copyright (C) 2023 Mavridis Philippe <mavridisf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
// TQt
|
||||
#include <tqhbox.h>
|
||||
#include <tqlabel.h>
|
||||
|
||||
// TDE
|
||||
#include <kiconloader.h>
|
||||
#include <tdeglobal.h>
|
||||
#include <tdelocale.h>
|
||||
|
||||
// Part
|
||||
#include "libmpv_part.h"
|
||||
#include "libmpv_errordlg.h"
|
||||
|
||||
/******************************/
|
||||
/***** Error Dialog *****/
|
||||
/******************************/
|
||||
MpvErrorDlg::MpvErrorDlg(MpvPart *part)
|
||||
: KDialogBase(0, 0, true, i18n("Error"),
|
||||
KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3,
|
||||
KDialogBase::User1, false,
|
||||
KGuiItem(i18n("Ignore"), "media-playback-start", i18n("Ignore error and continue playback")),
|
||||
KGuiItem(i18n("Stop"), "media-playback-stop", i18n("Stop playback")),
|
||||
KGuiItem(i18n("View Log"), "text-x-log", i18n("Pause playback and view event log"))),
|
||||
m_part(part)
|
||||
{
|
||||
TQHBox *hbox = makeHBoxMainWidget();
|
||||
|
||||
TQLabel *errorPix = new TQLabel(hbox);
|
||||
errorPix->setPixmap(TDEGlobal::iconLoader()->loadIcon("messagebox_warning",
|
||||
TDEIcon::NoGroup, TDEIcon::SizeMedium, TDEIcon::DefaultState));
|
||||
|
||||
TQLabel *errorMsg = new TQLabel(i18n("An error has occurred, but Kaffeine can continue playing the current file.\n"
|
||||
"You can view the event log to check for details."), hbox);
|
||||
errorMsg->setAlignment(TQt::AlignLeft | TQt::AlignTop);
|
||||
|
||||
m_part->slotPause(true);
|
||||
}
|
||||
|
||||
MpvErrorDlg::~MpvErrorDlg() {
|
||||
}
|
||||
|
||||
/*** Ignore error and continue playback ***/
|
||||
void MpvErrorDlg::slotUser1() {
|
||||
m_part->slotPlay();
|
||||
accept();
|
||||
}
|
||||
|
||||
/*** Stop playback ***/
|
||||
void MpvErrorDlg::slotUser2() {
|
||||
m_part->slotStop();
|
||||
accept();
|
||||
}
|
||||
|
||||
/*** Pause playback and view event log ***/
|
||||
void MpvErrorDlg::slotUser3() {
|
||||
m_part->slotViewLog();
|
||||
accept();
|
||||
}
|
||||
/******************************/
|
||||
/***** Fatal Error Dialog *****/
|
||||
/******************************/
|
||||
MpvFatalErrorDlg::MpvFatalErrorDlg(MpvPart *part)
|
||||
: KDialogBase(0, 0, true, i18n("Fatal Error"),
|
||||
KDialogBase::User1 | KDialogBase::User2,
|
||||
KDialogBase::User1, false,
|
||||
KGuiItem(i18n("Stop"), "media-playback-stop", i18n("Stop playback")),
|
||||
KGuiItem(i18n("View Log"), "text-x-log", i18n("Stop playback and view event log"))),
|
||||
m_part(part)
|
||||
{
|
||||
TQHBox *hbox = makeHBoxMainWidget();
|
||||
|
||||
TQLabel *errorPix = new TQLabel(hbox);
|
||||
errorPix->setPixmap(TDEGlobal::iconLoader()->loadIcon("messagebox_critical",
|
||||
TDEIcon::NoGroup, TDEIcon::SizeMedium, TDEIcon::DefaultState));
|
||||
|
||||
TQLabel *errorMsg = new TQLabel(i18n("A fatal error has occurred and Kaffeine cannot continue playback."), hbox);
|
||||
errorMsg->setAlignment(TQt::AlignLeft | TQt::AlignTop);
|
||||
|
||||
m_part->slotStop();
|
||||
}
|
||||
|
||||
MpvFatalErrorDlg::~MpvFatalErrorDlg() {
|
||||
}
|
||||
|
||||
/*** Stop playback ***/
|
||||
void MpvFatalErrorDlg::slotUser1() {
|
||||
accept(); // already stopped
|
||||
}
|
||||
|
||||
/*** Stop playback and view event log ***/
|
||||
void MpvFatalErrorDlg::slotUser2() {
|
||||
m_part->slotViewLog();
|
||||
accept(); // already stopped
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Kaffeine libmpv part
|
||||
* Copyright (C) 2023 Mavridis Philippe <mavridisf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __LIBMPVERRORDLG_H__
|
||||
#define __LIBMPVERRORDLG_H__
|
||||
|
||||
// TDE
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class MpvPart;
|
||||
|
||||
class MpvErrorDlg : public KDialogBase {
|
||||
public:
|
||||
MpvErrorDlg(MpvPart *part);
|
||||
~MpvErrorDlg();
|
||||
|
||||
protected slots:
|
||||
void slotUser1(); // ignore
|
||||
void slotUser2(); // stop
|
||||
void slotUser3(); // view log
|
||||
|
||||
private:
|
||||
MpvPart *m_part;
|
||||
};
|
||||
|
||||
class MpvFatalErrorDlg : public KDialogBase {
|
||||
public:
|
||||
MpvFatalErrorDlg(MpvPart *part);
|
||||
~MpvFatalErrorDlg();
|
||||
|
||||
protected slots:
|
||||
void slotUser1(); // stop
|
||||
void slotUser2(); // view log
|
||||
|
||||
private:
|
||||
MpvPart *m_part;
|
||||
};
|
||||
|
||||
#endif // __LIBMPVERRORDLG_H__
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Kaffeine libmpv part
|
||||
* Copyright (C) 2023 Mavridis Philippe <mavridisf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
// TQt
|
||||
#include <tqapplication.h>
|
||||
#include <tqclipboard.h>
|
||||
#include <tqlistview.h>
|
||||
#include <tqtextstream.h>
|
||||
|
||||
// TDE
|
||||
#include <tdemessagebox.h>
|
||||
#include <kiconloader.h>
|
||||
#include <tdeglobal.h>
|
||||
#include <tdelocale.h>
|
||||
|
||||
// Part
|
||||
#include "libmpv_event.h"
|
||||
#include "libmpv_part.h"
|
||||
#include "libmpv_log.h"
|
||||
|
||||
MpvLogViewerDlg::MpvLogViewerDlg(MpvPart *part)
|
||||
: KDialogBase(0, 0, false, i18n("MPV log"),
|
||||
KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3 | KDialogBase::Close,
|
||||
KDialogBase::Close, false,
|
||||
KGuiItem(i18n("Clear"), "clear_left", "Clear MPV event log"),
|
||||
KGuiItem(i18n("Refresh"), "reload", "Refresh MPV event log"),
|
||||
KGuiItem(i18n("Copy"), "edit-copy", "Copy selected line")),
|
||||
m_part(part)
|
||||
{
|
||||
m_logView = new TQListView(this);
|
||||
m_logView->addColumn("Level");
|
||||
m_logView->addColumn("Timestamp");
|
||||
m_logView->addColumn("Prefix");
|
||||
m_logView->addColumn("Message");
|
||||
m_logView->setResizeMode(TQListView::LastColumn);
|
||||
m_logView->setSorting(1);
|
||||
m_logView->setAllColumnsShowFocus(true);
|
||||
setMainWidget(m_logView);
|
||||
resize(500, 250);
|
||||
|
||||
refreshLog();
|
||||
}
|
||||
|
||||
MpvLogViewerDlg::~MpvLogViewerDlg() {
|
||||
delete m_logView;
|
||||
}
|
||||
|
||||
void MpvLogViewerDlg::refreshLog() {
|
||||
TDEIconLoader *icoLoad = TDEGlobal::iconLoader();
|
||||
|
||||
m_logView->clear();
|
||||
|
||||
TQValueList<struct MpvEventData>::iterator it;
|
||||
for (it = m_part->m_eventLog.begin();
|
||||
it != m_part->m_eventLog.end();
|
||||
++it)
|
||||
{
|
||||
TQString timestamp ((*it).timestamp.toString()),
|
||||
level ((*it).level),
|
||||
prefix ((*it).prefix),
|
||||
message ((*it).text.replace("\n", ""));
|
||||
|
||||
TQListViewItem *li = new TQListViewItem(m_logView, level, timestamp,
|
||||
prefix, message);
|
||||
|
||||
TQString icon;
|
||||
if (level == "error" || level == "fatal") {
|
||||
icon = "messagebox_critical";
|
||||
}
|
||||
|
||||
else if (level == "warn") {
|
||||
icon = "messagebox_warning";
|
||||
}
|
||||
|
||||
else {
|
||||
icon = "messagebox_info";
|
||||
}
|
||||
|
||||
li->setPixmap(0, icoLoad->loadIcon(icon, TDEIcon::Small));
|
||||
}
|
||||
}
|
||||
|
||||
/*** Clear ***/
|
||||
void MpvLogViewerDlg::slotUser1() {
|
||||
int ret = KMessageBox::questionYesNo(this,
|
||||
i18n("Would you like to clear the MPV log?"),
|
||||
i18n("Clear log?"));
|
||||
|
||||
if (ret == KMessageBox::Yes) {
|
||||
m_part->m_eventLog.clear();
|
||||
refreshLog();
|
||||
}
|
||||
}
|
||||
|
||||
/*** Refresh ***/
|
||||
void MpvLogViewerDlg::slotUser2() {
|
||||
refreshLog();
|
||||
}
|
||||
|
||||
/*** Copy selection ***/
|
||||
void MpvLogViewerDlg::slotUser3() {
|
||||
TQClipboard *clip = TQApplication::clipboard();
|
||||
TQString logLineTemplate = TQString("[%1] (%2 %3) %4");
|
||||
|
||||
TQListViewItem *sel = m_logView->selectedItem();
|
||||
if (!sel) {
|
||||
int ret = KMessageBox::warningYesNo(this,
|
||||
i18n("Would you like to copy the whole MPV log?"),
|
||||
i18n("Copy whole log?"));
|
||||
|
||||
if (ret != KMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TQString out;
|
||||
TQTextStream ts(&out, IO_WriteOnly);
|
||||
TQListViewItemIterator it(m_logView);
|
||||
while (it.current()) {
|
||||
if (!sel || it.current()->isSelected()) {
|
||||
ts << logLineTemplate.arg(
|
||||
(*it)->text(1), (*it)->text(0),
|
||||
(*it)->text(2), (*it)->text(3))
|
||||
<< endl;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
clip->setText(out);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Kaffeine libmpv part
|
||||
* Copyright (C) 2023 Mavridis Philippe <mavridisf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __LIBMPVLOG_H__
|
||||
#define __LIBMPVLOG_H__
|
||||
|
||||
// TDE
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class MpvPart;
|
||||
class TQListView;
|
||||
|
||||
class MpvLogViewerDlg : public KDialogBase {
|
||||
public:
|
||||
MpvLogViewerDlg(MpvPart *part);
|
||||
~MpvLogViewerDlg();
|
||||
|
||||
protected slots:
|
||||
void slotUser1(); // clear
|
||||
void slotUser2(); // refresh
|
||||
void slotUser3(); // copy selection
|
||||
|
||||
private:
|
||||
void refreshLog();
|
||||
|
||||
private:
|
||||
MpvPart *m_part;
|
||||
TQListView *m_logView;
|
||||
};
|
||||
|
||||
#endif // __LIBMPVLOG_H__
|
Loading…
Reference in new issue