#ifndef COMMON_HPP
#define COMMON_HPP

#include "config.h"

#include <string>
#include <list>
#include <vector>

#include "input.hpp"
#include "image.hpp"

// overlay
#include "image.hpp"

//mypair
typedef std::pair<std::string, std::string> MyPair;
const MyPair emptyMyPair = MyPair("","");

enum Scaling { SCALE_FULL, SCALE_VERTICAL, SCALE_HORIZONTAL, NOSCALING };

namespace conv {
  int atoi(const std::string& s);
  std::string itos(int i);
  std::string ftos(float f);
  bool stob(const std::string& s);
  std::string btos(bool b);
}

namespace string_format {
  void format_to_size(std::string& s, const std::string& font, int size, bool dots, bool long_string = false);
  // if a string is longer than maxlen, where maxlen is in number of chars, 
  // pps will transform the string into: the start, ..., the end of the string
  void pretty_print_string(std::string& s, int maxlen);
  // convertes // to /, useful for path prettyprinting
  std::string remove_doubles(const std::string& doubles);
  std::string lowercase(std::string s);
  // trims spaces, tabs and newline off the start and end of a string
  std::string trim(std::string s);
  void calculate_string_size(const std::string& text, const std::string& font, 
			     int *text_w, int *text_h);
  std::string get_line(const std::string& text, int &pos, int width, const std::string& font);
  // return the difference in the number of chars between two strings
  int difference(const std::string& lhs, const std::string& rhs);
  // convert a string in local format to UTF-8
  std::string convert(const std::string& in, bool mp3_locale = false);
}

// rounds to nearest int
const int round_to_int(double number);

const int min(int time);
const int sec(int time);

// can also check if a dir exists
bool file_exists(const std::string& filename);
void create_if_not_exists(const std::string& dir);

template<typename T>
inline T vector_lookup(const std::vector<T>& v, unsigned int pos)
{
#ifdef gcc_ver_major_3
  return v.at(pos);
#endif
#ifdef gcc_ver_major_2
  return v[pos];
#endif
}

namespace run
{
  int my_system_no_kill(const char *command);
  int my_system(const char *command);
}

// step1 displays the dialog on the screen. The dialog won't be cleared before
// step2 has been called. Useful when one doesn't know how long the dialog
// should be displayed
void print_dialog_step1(const std::list<std::string>& messages, Overlay &o);
void print_dialog_step2(Overlay &o);
// waits for keypress
void print_dialog(const std::list<std::string>& messages);
// this is a wrapper for print_dialog_time_wait. time in ms
void print_dialog_wait(const std::list<std::string>& messages, int time);
// time in ms
void print_dialog_time_wait(const std::list<std::string>& messages, Overlay& overlay, int time = 500);
// size is the vertical size, its placed in the middle of the screen
Input print_dialog_fixed_size(const std::string& message, int size, Overlay& dialog);

void cleanup_progressbar();
void print_progressbar();
int check_progressbar();

void register_keypress(Input input);
bool general_loop_check(Input input, bool disable_mode_change = false);

void clean_up(int signal);
void deinit_mms(bool from_cleanup);
 
#endif
