Note

A Hildon::Note can be used to display small informational dialogs. As with a normal Gtk::Dialog, these may contain buttons. A special feature is the possibility to display a dialog with a progress bar and a cancel button.

Note Reference

Example

Figure 5.10. Note

Note

This example shows some ways of using a Hildon::Note.

Source Code

File: examplewindow.h

#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <hildonmm/window.h>
#include <hildonmm/note.h>
#include <gtkmm.h>

class ExampleWindow : public Hildon::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  virtual void on_menu_quit();
  virtual void on_button();
  
  Gtk::Menu m_main;
  
  Gtk::MenuItem m_item_quit;
  
  Gtk::VBox m_vbox;
 
  Gtk::Button m_button;
  
  Gtk::ProgressBar m_bar;
  Hildon::Note* m_note;
  int m_type;
};

#endif //GTKMM_EXAMPLEWINDOW_H

File: examplewindow.cc

#include "examplewindow.h"
#include <gtkmm.h>
#include <hildonmm/note.h>
#include <iostream>

ExampleWindow::ExampleWindow() :
  m_item_quit("Quit"),
  m_button("Show Note"),
  m_vbox(true, 5)
{    
  // Add menu items to right menus
  m_main.append(m_item_quit);
  m_item_quit.show();
  m_main.show_all();
  
  set_main_menu(m_main);

  // Attach the callback functions to the activate signal
  m_item_quit.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_menu_quit) );
  
  m_button.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button));
  
  add(m_vbox);
  m_vbox.pack_start(m_button);
  
  m_type = 1;
  
  // Make all menu widgets visible
  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_menu_quit()
{
  hide();
}

void ExampleWindow::on_button()
{
  switch (m_type)
  {
    case 1:
    {
      Hildon::Note note1("Very important information", Gtk::Stock::NEW);
      note1.run();
      break;
    }
    case 2:
    {
      Hildon::Note note3 (Hildon::NOTE_TYPE_CONFIRMATION_BUTTON, 
          "Do you agree?");
      note3.add_button(Gtk::Stock::YES, Gtk::RESPONSE_YES);
      note3.add_button(Gtk::Stock::NO, Gtk::RESPONSE_NO);
      
      note3.run();
      break;
    }
    case 3:
    {
      Hildon::Note note4 (Hildon::NOTE_TYPE_INFORMATION, 
          "Info Simple!");
      note4.run();
      break;
    }
    case 4:
    {
      m_note = new Hildon::Note ("Note with Progressbar", Gtk::Stock::NEW, m_bar);
      m_bar.set_fraction(0.5);
      m_note->run();
      delete m_note;
    }
  }
  m_type++;
  if(m_type == 5)
    m_type = 1;
}

File: main.cc

#include <hildonmm.h>
#include "examplewindow.h"
#include <iostream>

int main(int argc, char *argv[])
{
  // Initialize gtkmm and maemomm:
  Gtk::Main kit(&argc, &argv);
  Hildon::init();

  osso_context_t* osso_context = osso_initialize("example", "0.0.1", TRUE /* deprecated parameter */, 0 /* Use default Glib main loop context */);
  if(!osso_context)
    std::cerr << "osso_initialize() failed." << std::endl;

  Glib::set_application_name("Note example");

  // Create Window and set it to Program 
  ExampleWindow window;
  Hildon::Program::get_instance()->add_window(window);

  // Begin the main application
  kit.run(window);

  osso_deinitialize(osso_context);
  
  return 0;
}