Skip to content

Instantly share code, notes, and snippets.

@Izaron
Last active Feb 26, 2017
Embed
What would you like to do?

Creating CCExtractor solid application for Gnome Software

CCExtractor is the tool for extracting subtitles from a tons of video file formats. My idea is to create statically built application with GUI.

Warning: I won't participate in GSoC 2017, so anyone can take this.

Part 1. CCExtractor as C library

We should not use CCExtractor binary and GUI apart. The first step - write some code so that it will be possible to use CCExtractor as a C library. The current version of the program does not allow us to call the code as the library, so it's first part.

The main() function is in ccextractor.c, and we will compile ccextractor.c, if we want to build binary file. If we want to build library files, we should compile ccextractorapi.h and ccextractorapi.cpp. Very alpha-version of ccextractorapi.h":

#ifndef CCEXTRACTORAPI_H
#define CCEXTRACTORAPI_H

/* Includies */

struct CCExtractorAPIParams;

struct CCExtractorAPIParams* CCExtractorAPIInit();
void CCExtractorAPIAddParam(struct CCExtractorAPIParams* params, char* arg);
int CCExtractorAPICompileParams(struct CCExtractorAPIParams* params, char** output);
void CCExtractorAPISetOutput(struct CCExtractorAPIParams* params, char** output);
void CCExtractorAPIStart(struct CCExtractorAPIParams* params);
void CCExtractorAPIStop(struct CCExtractorAPIParams* params);
double CCExtractorAPIGetPercents(struct CCExtractorAPIParams* params);

#endif //CCEXTRACTORAPI_H

Very aplha-version of project what can use library:

#include <ccextractorapi.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    struct CCExtractorAPIParams* par = CCExtractorAPIInit();
    for (int i = 1; i < argc; i++)
        CCExtractorAPIAddParam(par, argv[i]);
    if (!CCExtractorAPICompileParams(par, NULL))
        return -1;
    CCExtractorAPIStart(par);
    while (1) {
        /* Maybe we have to start CCExtractor in the other thread */
        int per = CCExtractorAPIGetPercents(par);
        printf("%ld\n", per);
        if (per >= 100.0)
            break;
    }
    return 0;
}

For Windows we will have .dll and .lib files of CCExtractor, for Linux .so and .a files. This part of the work should be done carefully - as you can see, we can have to start new thread for CCExtractor. And yes, you'll have to fix this issue - CCExtractor/ccextractor#692 Since you will use CMake

Part 2. Using GTK+ library for Gnome app

GTK+ is cool widget library. Many world-name apps was written in GTK+. For example Nautilus (file manager) and Rhytmbox (for music), what are pre-installed in Ubuntu and many others linux distros. So, almost all Gnome projects and applications use GTK+ library. But you don't have to learn this library for months. See the hints below.

Gnome Builder

Gnome Builder is in actively development specifically for these applications. The main languages for developers is C, C++ and Vala. You can also use one of the bindings that could be not supported in Builder - for example, some apps use Python (supported in Builder, but rare for projects) or JavaScript. But remember that C language is the most "orthodox" way.

GUI designing

The best way is to using Glade This thing is very similar to WinForms or QtBuilder. If you have ccextractor.glade, then you can simple:

static GtkWidget*
create_window (void)
{
        GtkWidget *window;
        GtkBuilder *builder;
        GError* error = NULL;
        builder = gtk_builder_new ();
        if (!gtk_builder_add_from_file (builder, "ccextractor.glade", &error))
        {
                g_critical ("Can't load file: %s", error->message);
                g_error_free (error);
        }
        gtk_builder_connect_signals (builder, NULL);
        window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
        if (!window)
                g_critical ("Some error");
        g_object_unref (builder);
        return window;
}

int
main (int argc, char *argv[])
{
        GtkWidget *window;
        gtk_init (&argc, &argv);
        window = create_window ();
        gtk_widget_show (window);
        gtk_main ();
        return 0;
}

^ There may be obsolete code, but you will read docs about newest GTK+, isn't you? Can be hard task - how to write libccextractor right and link to your UI project. There can be problems with additional libraries such as FFMPEG, but you should be able to catch them. Other task is how to design a beautiful UI with some feedback - for example link to Github project.

Gnome Software

Imagine that you have Gnome Desktop. You can launch pre-installed Gnome Software image

image Go to "Audio & Video"

image Hmm, where is CCExtractor? You need to add your application - see this https://wiki.gnome.org/Apps/Template See other app's descriptions. I don't know exactly if Gnome community have cruel premoderation of all apps, but if you have adequate app created, all should be OK.

Part ∞. Next improvements

  • [Good] Translate app to other languages. GTK+ and Glade allows you to have translated apps.
  • [Neutral] Add libmatroska. Since we don't want to have .mkv video support in ccextractor, but many users wants, then we can integrate this library to our app, but this can be painfully. Also libmatroska written in C++, so you have to call C++ code in C/Vala/Python/(your lang)
  • [Good] Convert libccextractor to other languages. Python, Java, C# or other adequate languages
  • [Goooood] See other software centers. For example "Ubuntu Software Center". If you don't know, in Gnome Software there are many apps written on Qt, so you won't be punished in "wrong graphical library".

IT CAN BE VERY HARD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment