Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Audacious plugin for opening folder containing playlist files in KDE Dolphin file browser
/*
* aud-view-dir.cc - An Audacious plugin for opening the folder where files in
* the playlist are located. Currently supports KDE Dolphin.
*
* Build with: g++ -Wall -std=c++11 -fPIC -shared aud-view-dir.cc $(pkg-config gtk+-2.0 audacious --cflags --libs) -o aud-view-dir.so
*
* Copy .so file into system Audiacious plugin directory, because
* plugins in ~/.local aren't loaded by Audacious anymore.
*
* Copyright 2015 Boris Gjenero
* Based on delete-files.c, Copyright 2013 John Lindgren
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions, and the following disclaimer in the documentation
* provided with the distribution.
*
* This software is provided "as is" and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising from
* the use of this software.
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <libaudcore/i18n.h>
#include <libaudcore/playlist.h>
#include <libaudcore/plugin.h>
#include <libaudcore/audstrings.h>
#include <libaudcore/interface.h>
class AudViewDir : public GeneralPlugin
{
public:
static const char about[];
static constexpr PluginInfo info = {
N_("Open File Location"),
"standalone",
// about,
};
constexpr AudViewDir () : GeneralPlugin (info, false) {}
bool init ();
void cleanup ();
};
__attribute__((visibility("default"))) AudViewDir aud_plugin_instance;
static AudMenuID menus[] = { AudMenuID::Main, AudMenuID::Playlist };
static void view_files(void)
{
Index<String> files;
int playlist = aud_playlist_get_active();
int entry_count = aud_playlist_entry_count(playlist);
for (int i = 0; i < entry_count; i ++)
{
if (aud_playlist_entry_get_selected (playlist, i))
files.append (aud_playlist_entry_get_filename (playlist, i));
}
int file_count = files.len();
/* This is wrong because string constants end up assigned to non-const
* pointers. Why would g_spawn_async() not have a const argv parameter?
* Anyways, it works, and for this simple plugin, I just don't care.
*/
gchar **argv = g_new(gchar *, file_count + 3);
#if 0
argv[0] = "/usr/bin/dolphin";
argv[1] = "--select";
#else
argv[0] = "/usr/bin/nemo";
argv[1] = "-n";
#endif
argv[file_count + 2] = NULL;
for(int i = 0; i < file_count; i ++) {
argv[i + 2] = (gchar *)(const char *)files[i];
}
g_spawn_async(NULL,
argv,
NULL,
G_SPAWN_DEFAULT,
NULL,
NULL,
NULL,
NULL);
g_free(argv);
}
bool AudViewDir::init(void)
{
for(AudMenuID menu : menus)
aud_plugin_menu_add(menu, view_files,
"Open File Location",
"document-open-folder");
return TRUE;
}
void AudViewDir::cleanup(void)
{
for(AudMenuID menu : menus)
aud_plugin_menu_remove(menu, view_files);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment