Commit d335e0d0 authored by Pipelier Quentin's avatar Pipelier Quentin
Browse files

[+] Mise en place de la liste en fonction des playlists dans le répertoire...

[+] Mise en place de la liste en fonction des playlists dans le répertoire courant, TODO: ajout de la taille
parent 20c6cc85
Pipeline #200193 passed with stages
in 21 minutes and 37 seconds
This diff is collapsed.
......@@ -8,6 +8,21 @@ class Interface{
protected:
public:
Interface(int argc, char* argv[]);
class ModelColumns : public Gtk::TreeModel::ColumnRecord {
public:
ModelColumns(){
add(m_col_id); add(m_col_name); add(m_col_format); add(m_col_taille);}
Gtk::TreeModelColumn<unsigned int> m_col_id;
Gtk::TreeModelColumn<Glib::ustring> m_col_name;
Gtk::TreeModelColumn<Glib::ustring> m_col_format;
Gtk::TreeModelColumn<int> m_col_taille;
};
ModelColumns m_Columns;
void addElementPlaylist(Glib::RefPtr<Gtk::ListStore> m_refTreeModel);
};
#endif
#include "../header/interface.h"
#include <dirent.h>
#include <iostream>
#include <string>
#include <sys/types.h>
Interface::Interface(int argc, char* argv[])
{
Gtk::Main app(argc, argv);
Gtk::Window window;
Gtk::Label label;
Gtk::Label label2;
Gtk::Notebook selector;
Gtk::Grid grid;
......@@ -20,20 +23,50 @@ Interface::Interface(int argc, char* argv[])
Gtk::Entry entry_name_playlist;
entry_name_playlist.set_max_length(50);
Gtk::Label label_name_playlist;
label_name_playlist.set_text("Saisir le nom: ");
grid.attach(label_name_playlist, 0, 0, 1, 1);
Gtk::Label label_duration_playlist;
label_duration_playlist.set_text("Saisir la durée: ");
grid.attach(label_duration_playlist, 1, 0, 1, 1);
Gtk::Entry entry_duration_playlist;
grid.attach(entry_name_playlist, 0, 0, 1, 1);
grid.attach(entry_duration_playlist, 1, 0, 1, 1);
grid.attach(entry_name_playlist, 0, 0, 2, 1);
grid.attach(entry_duration_playlist, 1, 0, 2, 1);
button_generate.add_label("Générer");
grid.attach(button_generate, 0, 1, 2, 1);
grid.attach(button_generate, 0, 1, 3, 1);
grid.show_all();
label.set_text("page 1");
// Liste des playlists
Gtk::ScrolledWindow m_ScrolledWindow;
Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
Gtk::Box m_VBox;
m_ScrolledWindow.add(m_TreeView);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
m_VBox.pack_start(m_ScrolledWindow);
m_refTreeModel = Gtk::ListStore::create(m_Columns);
m_TreeView.set_model(m_refTreeModel);
// Ajout des fichiers playlists à la liste
addElementPlaylist(m_refTreeModel);
m_TreeView.append_column("Id", m_Columns.m_col_id);
m_TreeView.append_column("Nom", m_Columns.m_col_name);
m_TreeView.append_column("Format", m_Columns.m_col_format);
m_TreeView.append_column("Taille", m_Columns.m_col_taille);
selector.append_page(label, "Listes des playlists");
selector.append_page(m_VBox, "Listes des playlists");
selector.append_page(grid, "Créer une playlist");
window.add(selector);
......@@ -41,3 +74,46 @@ Interface::Interface(int argc, char* argv[])
Gtk::Main::run(window);
}
void Interface::addElementPlaylist(Glib::RefPtr<Gtk::ListStore> m_refTreeModel){
const char*path = "./";
std::string xspf = ".xspf";
std::string m3u = ".m3u";
struct dirent *entry;
DIR *dir = opendir(path);
int count = 0;
if(dir == NULL){
std::cerr << "Erreur, dossier null";
}else{
while((entry = readdir(dir)) != NULL){
if(std::string(entry->d_name).find(xspf) != std::string::npos){
Gtk::TreeModel::Row row = *(m_refTreeModel->append());
count++;
std::string name = std::string(entry->d_name).erase(std::string(entry->d_name).size()-5);
row[m_Columns.m_col_id] = count;
row[m_Columns.m_col_name] = name;
row[m_Columns.m_col_format] = "XSPF";
row[m_Columns.m_col_taille] = 0;
}else if(std::string(entry->d_name).find(m3u) != std::string::npos){
Gtk::TreeModel::Row row = *(m_refTreeModel->append());
count++;
std::string name = std::string(entry->d_name).erase(std::string(entry->d_name).size()-4);
row[m_Columns.m_col_id] = count;
row[m_Columns.m_col_name] = name;
row[m_Columns.m_col_format] = "M3U";
row[m_Columns.m_col_taille] = 0;
}
}
closedir(dir);
}
}
......@@ -60,7 +60,6 @@ int main(int nombre_de_parametres, char *tableau_des_parametres[])
logger.log_info("Database connection success");
if(interface){
std::cout << "ok";
Interface *interface = new Interface(nombre_de_parametres, tableau_des_parametres);
}else{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment