Baka-MPlayer icon indicating copy to clipboard operation
Baka-MPlayer copied to clipboard

Open with not working on OSX

Open ghost opened this issue 9 years ago • 3 comments

Right-click -> open with -> other.. -> select baka-mplayer -> ok This loads up baka-mplayer but doesn't load up the file. Should probably look into how OSX gives arguments to applications.

ghost avatar Aug 22 '15 14:08 ghost

Looking at this, I'm under the impression that Mac OSX is passing other arguments--Baka would then try to open those, maybe i'll just ignore things that start with '-' to fix it.

u8sand avatar Aug 22 '15 15:08 u8sand

void BakaEngine::Open()
{
    mpv->LoadFile(QFileDialog::getOpenFileName(window,
                   tr("Open File"),mpv->getPath(),
                   QString("%0 (%1);;").arg(tr("Media Files"), Mpv::media_filetypes.join(" "))+
                   QString("%0 (%1);;").arg(tr("Video Files"), Mpv::video_filetypes.join(" "))+
                   QString("%0 (%1);;").arg(tr("Audio Files"), Mpv::audio_filetypes.join(" "))+
                   QString("%0 (*.*)").arg(tr("All Files")),
                   0, QFileDialog::DontUseSheet));
}

kennydiff avatar May 12 '17 14:05 kennydiff

@KennyDiff this line of code is for the OpenFile dialog. Files that are opened through a file manager should get passed arguments of the opened file. It works the way it should on Windows and Linux, not sure why OSX is different. It may very well be passing extra stuff that we ignore in our very primitive command-line argument handling (we just try to load the first argument).

int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
    FreeConsole();
#endif
    QApplication a(argc, argv);
    setlocale(LC_NUMERIC, "C"); // for mpv

    MainWindow w;
    w.show();

    // parse command line
    QStringList args = QApplication::arguments(); // <-- here we get command line args
    QStringList::iterator arg = args.begin();
    if(++arg != args.end())
        w.Load(*arg); // <-- here we try to play the argument
    else
        w.Load();

    return a.exec();
}

If you're able to debug this--simply print out what args is. You might want to try skipping - preceded arguments.

while(++arg != args.end() && arg.startsWith("-"));
if(arg != args.end())
  w.Load(*arg);
else
  w.Load();

u8sand avatar May 13 '17 14:05 u8sand