File: utils.h

package info (click to toggle)
tea 28.1.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,520 kB
  • ctags: 1,556
  • sloc: cpp: 10,148; ansic: 2,960; xml: 2,732; makefile: 7
file content (152 lines) | stat: -rw-r--r-- 5,193 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
 *   Copyright (C) 2007-2010 by Peter Semiletov                            *
 *   peter.semiletov@gmail.com                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef UTILS_H
#define UTILS_H

#include <QtGui>


typedef struct {
                char chunk_id[4];
                quint32 chunk_size;
               } t_wav_chunk_hdr;


typedef struct {
                quint16 format;      // = 1 (PCM/uncompressed)
                quint16 num_channels; // mono = 1, stereo = 2, etc
                quint32 sample_rate;  // 8000, 44100, 48000 etc
                quint32 byte_rate;    // SampleRate * NumChannels * BitsPerSample/8
                quint16 block_align;  // NumChannels * BitsPerSample / 8
                quint16 bits_per_sample; //8, 16 etc
               } t_wav_chunk_fmt;



class CFilesList: public QObject
{
public:

  QStringList list;

  void get (const QString &path);
  void iterate (QFileInfo &fi);
};


class CFTypeChecker: public QObject
{
public:

  QStringList lexts;
  QStringList lnames;

  CFTypeChecker (const QString &fnames, const QString &exts);
  bool check (const QString &fname);
};


class CWavReader: public QObject
{
public:

  t_wav_chunk_fmt wav_chunk_fmt;
  double rms;
  bool get_info (const QString fname);
};

QString hash_keyval_to_string (const QHash<QString, QString> &h);
QString hash_get_val (QHash<QString, QString> &h, const QString &key, const QString &def_val);

QString file_get_ext (const QString &file_name);

bool file_exists (const QString &fileName);
void qstring_list_print (const QStringList &l);

bool qstring_save (const QString &fileName, const QString &data, const char *enc = "UTF-8");
QString qstring_load (const QString &fileName, const char *enc = "UTF-8");

QString toggle_fname_header_source (const QString &fileName);


void create_menu_from_list (QObject *handler,
                            QMenu *menu,
                            const QStringList &list,
                            const char *method
                           );

QString mod_to_string (Qt::KeyboardModifiers k);
QStringList read_dir_entries (const QString &path);
QStringList html_get_by_patt (const QString &s, const QString &spatt);
QHash<QString, QString> hash_load (const QString &fname);
QHash<QString, QString> hash_load_keyval (const QString &fname);
QHash<QString, QString> stringlist_to_hash (const QStringList &l);
QString hash_keyval_to_string (QHash<QString, QString> *h);
bool is_image (const QString &filename);
QString keycode_to_string (int k);
QString string_between (const QString &source, const QString &sep1, const QString &sep2);
QByteArray file_load (const QString &fileName);

bool char_is_shit (const QChar &c);

void create_menu_from_dir (QObject *handler,
                           QMenu *menu,
                           const QString &dir,
                           const char *method
                           );
QPixmap pixmap_scale_by (const QPixmap &source,
                         bool by_side,
                         int value,
                         Qt::TransformationMode mode);

QString change_file_ext (const QString &s, const QString &ext);
QStringList bytearray_to_stringlist (QList <QByteArray> a);
QString qstring_get_last_after (const QString &s, const QString &sep);
QString int_to_binary (int n);
QString string_reverse (const QString &s);
unsigned int bin_to_decimal (const QString &s);
QString get_insert_image (const QString &file_name, const QString &full_path, const QString &markup_mode);


inline int get_value (int total, int perc)
{
  return static_cast <int> ((total / 100) * perc);
}


inline double get_percent (double total, double value)
{
  return (value / total) * 100;
}


inline bool is_dir (const QString &path)
{
  return QFileInfo(path).isDir();
}


inline QString get_file_path (const QString &fileName)
{
  return QFileInfo (fileName).absolutePath();
}

#endif