The Hildon::FileDetailsDialog is a simple dialog to show more information about a file. This information includes mime-type, modification date, location and size. You may append extra information to that dialog by adding an additional tab to contain your custom widgets. The file handling is done by Hildon::FileSystemModel which is a Gtk::TreeModel, and therefore uses Gtk::TreeIter to describe file locations on the device.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEDIALOG_H
#define _MAEMOMM_EXAMPLEDIALOG_H
#include <hildonmm/window.h>
#include <gtkmm/buttonbox.h>
#include <hildonmm/button.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_clicked();
// Child widgets:
Gtk::HButtonBox box_;
Hildon::Button button_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <hildon-fmmm/file-chooser-dialog.h>
#include <hildon-fmmm/file-details-dialog.h>
#include <iostream>
ExampleWindow::ExampleWindow() :
button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
Hildon::BUTTON_ARRANGEMENT_VERTICAL,
"Click Me",
"to select a file")
{
set_title("Hildon::FileDetailsDialog Example");
add(box_);
box_.pack_start(button_, Gtk::PACK_SHRINK);
button_.signal_clicked().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_clicked()
{
Hildon::FileChooserDialog dialog(*this, Gtk::FILE_CHOOSER_ACTION_OPEN);
Gtk::FileFilter filter_any;
filter_any.set_name("Any Files");
filter_any.add_pattern("*");
dialog.add_filter(filter_any);
//Show the dialog and wait for a user response:
int response = dialog.run();
//Handle the response:
switch(response)
{
case(Gtk::RESPONSE_OK):
{
const std::string filename = dialog.get_filename();
std::cout << "filename chosen: " << filename << std::endl;
// Create a Hildon::FileSystemModel
Glib::RefPtr<Hildon::FileSystemModel> fs_model =
Hildon::FileSystemModel::create(*this /* ref-widget */);
// Create a Hildon::FileDetailsDialog
Hildon::FileDetailsDialog fd_dialog(fs_model);
// Tell the FileDetailsDialog to show this file:
Gtk::TreeModel::iterator iter = fs_model->load_local_path(filename);
//TODO (low priority): load_local_path() always seems to return a null iter.
if(iter)
{
fd_dialog.set_file_iter(iter);
}
else
std::cerr << "Hildon::FileSystemModel::load_local_path(" << filename <<
") failed" << std::endl;
// Show the dialog:
fd_dialog.set_transient_for(*this);
fd_dialog.run();
break;
}
case(Gtk::RESPONSE_CANCEL):
{
std::cout << "Cancel clicked." << std::endl;
break;
}
default:
{
std::cerr << "Unexpected button clicked." << std::endl;
break;
}
}
}
File: main.cc
#include <hildonmm.h>
#include <hildon-fmmm.h>
#include "examplewindow.h"
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Hildon::init();
Hildon::fm_init();
ExampleWindow window;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}