Commit fa54872c authored by Urs Fleisch's avatar Urs Fleisch
Browse files

initial release

parent bea1abce
/**
* \file commandstable.cpp
* Context menu commands configuration table.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 10 Oct 2005
*/
#include "commandstable.h"
#include "config.h"
#ifdef CONFIG_USE_KDE
#include <klocale.h>
#else
#define i18n(s) tr(s)
#define I18N_NOOP(s) QT_TR_NOOP(s)
#endif
#if QT_VERSION >= 300
#include <qpopupmenu.h>
/**
* Constructor.
*
* @param title title
* @param parent parent widget
* @param name Qt object name
*/
CommandsTable::CommandsTable(QWidget* parent, const char* name) :
QTable(parent, name) {
setNumCols(2);
horizontalHeader()->setLabel(0, i18n("Confirm"));
horizontalHeader()->setLabel(1, i18n("Command"));
adjustColumn(0);
setColumnStretchable(1, true);
connect(this, SIGNAL(valueChanged(int, int)),
this, SLOT(valueChanged(int, int)));
connect(this, SIGNAL(contextMenuRequested(int, int, const QPoint&)),
this, SLOT(contextMenu(int, int, const QPoint&)));
}
/**
* Destructor.
*/
CommandsTable::~CommandsTable() {}
/**
* Called when a value in the table is changed.
* If the second cell in the last row is changed to a non-empty
* value, a new row is added. If it is changed to an empty value,
* the row is deleted.
*
* @param row table row of changed item
* @param col table column of changed item
*/
void CommandsTable::valueChanged(int row, int col)
{
if (row == numRows() - 1 && col == 1) {
if (text(row, col).isEmpty()) {
if (row != 0) {
deleteRow(row);
}
} else {
insertRow(row);
}
}
}
/**
* Insert a new row into the table.
*
* @param row the new row is inserted after this row
*/
void CommandsTable::insertRow(int row)
{
insertRows(row + 1);
setItem(row + 1, 0, new QCheckTableItem(this, ""));
}
/**
* Delete a row from the table.
*
* @param row row to delete
*/
void CommandsTable::deleteRow(int row)
{
removeRow(row);
}
/**
* Clear a row in the table.
*
* @param row row to clear
*/
void CommandsTable::clearRow(int row)
{
setText(row, 1, "");
QTableItem* ti = item(row, 0);
QCheckTableItem* cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
cti->setChecked(false);
}
}
/**
* Display context menu.
*
* @param row row at which context menu is displayed
* @param col column at which context menu is displayed
* @param pos position where context menu is drawn on screen
*/
void CommandsTable::contextMenu(int row, int /* col */, const QPoint& pos)
{
QPopupMenu menu(this);
if (row >= -1) {
menu.insertItem(i18n("&Insert row"), this, SLOT(insertRow(int)), 0, 0);
menu.setItemParameter(0, row);
}
if (row >= 0) {
menu.insertItem(i18n("&Delete row"), this, SLOT(deleteRow(int)), 0, 1);
menu.setItemParameter(1, row);
}
if (row >= 0) {
menu.insertItem(i18n("&Clear row"), this, SLOT(clearRow(int)), 0, 2);
menu.setItemParameter(2, row);
}
menu.setMouseTracking(true);
menu.exec(pos);
}
/**
* Set the table from the command list.
*
* @param cmdList command list
*/
void CommandsTable::setCommandList(const QStringList& cmdList)
{
setNumRows(0);
int row = 0;
for (QStringList::const_iterator it = cmdList.begin();
it != cmdList.end();
++it) {
QString cmd = *it;
bool confirm = false;
if (cmd[0] == '!') {
cmd = cmd.mid(1);
confirm = true;
}
if (!cmd.isEmpty()) {
insertRows(row);
QCheckTableItem* cti = new QCheckTableItem(this, "");
if (cti) {
cti->setChecked(confirm);
setItem(row, 0, cti);
}
setText(row, 1, cmd);
++row;
}
}
if (row == 0) {
// no commands => show at least one row
insertRow(-1);
}
}
/**
* Get the command list from the table.
*
* @param cmdList the command list is returned here
*/
void CommandsTable::getCommandList(QStringList& cmdList) const
{
cmdList.clear();
int nrRows = numRows();
for (int row = 0; row < nrRows; ++row) {
QString cmd = text(row, 1);
if (!cmd.isEmpty()) {
QTableItem* ti = item(row, 0);
QCheckTableItem* cti = dynamic_cast<QCheckTableItem*>(ti);
if (cti) {
if (cti->isChecked()) {
cmd = "!" + cmd;
}
}
cmdList.push_back(cmd);
}
}
}
#else
CommandsTable::CommandsTable(QWidget* parent, const char* name) :
QTable(parent, name) {}
CommandsTable::~CommandsTable() {}
void CommandsTable::valueChanged(int, int) {}
void CommandsTable::insertRow(int) {}
void CommandsTable::deleteRow(int) {}
void CommandsTable::clearRow(int) {}
void CommandsTable::contextMenu(int, int, const QPoint&) {}
void CommandsTable::setCommandList(const QStringList&) {}
void CommandsTable::getCommandList(QStringList&) const {}
#endif
/**
* \file commandstable.h
* Context menu commands configuration table.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 10 Oct 2005
*/
#ifndef COMMANDSTABLE_H
#define COMMANDSTABLE_H
#include <qtable.h>
class QStringList;
class CommandsTable : public QTable {
Q_OBJECT
public:
/**
* Constructor.
*
* @param title title
* @param parent parent widget
* @param name Qt object name
*/
CommandsTable(QWidget* parent = 0, const char* name = 0);
/**
* Destructor.
*/
virtual ~CommandsTable();
/**
* Set the table from the command list.
*
* @param cmdList command list
*/
void setCommandList(const QStringList& cmdList);
/**
* Get the command list from the table.
*
* @param cmdList the command list is returned here
*/
void getCommandList(QStringList& cmdList) const;
public slots:
/**
* Called when a value in the table is changed.
* If the second cell in the last row is changed to a non-empty
* value, a new row is added. If it is changed to an empty value,
* the row is deleted.
*
* @param row table row of changed item
* @param col table column of changed item
*/
void valueChanged(int row, int col);
/**
* Insert a new row into the table.
*
* @param row the new row is inserted after this row
*/
void insertRow(int row);
/**
* Delete a row from the table.
*
* @param row row to delete
*/
void deleteRow(int row);
/**
* Clear a row in the table.
*
* @param row row to clear
*/
void clearRow(int row_col);
/**
* Display context menu.
*
* @param row row at which context menu is displayed
* @param col column at which context menu is displayed
* @param pos position where context menu is drawn on screen
*/
void contextMenu(int row, int col, const QPoint& pos);
};
#endif // COMMANDSTABLE_H
/**
* \file dirlist.cpp
* List of directories to operate on.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 5 Jul 2005
*/
#include "dirlist.h"
#include <qfileinfo.h>
#include <qdir.h>
#include <qstringlist.h>
/**
* Constructor.
*/
DirList::DirList(QWidget* parent, const char* name, WFlags f) :
QListBox(parent, name, f) {}
/**
* Destructor.
*/
DirList::~DirList() {}
/**
* Fill the dirlist with the directories found in a directory.
*
* @param name path of directory
* @return false if name is not directory path, else true.
*/
bool DirList::readDir(const QString& name) {
QFileInfo file(name);
if(file.isDir()) {
clear();
m_dirname = name;
QDir dir(file.filePath());
insertStringList(dir.entryList(QDir::Dirs | QDir::Drives));
return true;
}
return false;
}
/**
* \file dirlist.h
* List of directories to operate on.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 5 Jul 2005
*/
#ifndef DIRLIST_H
#define DIRLIST_H
#include <qstring.h>
#include <qlistbox.h>
/**
* List of directories to operate on.
*/
class DirList : public QListBox {
public:
/**
* Constructor.
*/
DirList(QWidget* parent = 0, const char* name = 0, WFlags f = 0);
/**
* Destructor.
*/
virtual ~DirList();
/**
* Fill the dirlist with the directories found in a directory.
*
* @param name path of directory
* @return FALSE if name is not directory path, else TRUE.
*/
bool readDir(const QString& name);
/**
* Get path of directory.
*
* @return absolute path of directory.
*/
QString getDirname(void) const { return m_dirname; }
private:
/** path of directory */
QString m_dirname;
};
#endif // DIRLIST_H
msgid "&File"
msgstr "&Archivo"
msgid "&Open..."
msgstr "&Abrir..."
msgid "&Save"
msgstr "&Guardar"
msgid "&Quit"
msgstr "&Salir"
msgid "&Help"
msgstr "A&yuda"
msgid "Open"
msgstr "Abrir"
msgid "Copy"
msgstr "Copiar"
msgid "Paste"
msgstr "Pegar"
msgid "Remove"
msgstr "Eliminar"
msgid "Edit"
msgstr "Editar"
msgid "Add"
msgstr "Añadir"
msgid "Delete"
msgstr "Eliminar"
msgid "Look &in:"
msgstr "Mirar &en:"
msgid "File &name:"
msgstr "&Nombre de archivo:"
msgid "File &type:"
msgstr "&Tipo de fichero:"
msgid "Cancel"
msgstr "Cancelar"
msgid "Import"
msgstr "Importar"
msgid "Export"
msgstr "Exportar"
msgid "View"
msgstr "Ver"
msgid "Revert"
msgstr "&Deshacer"
msgid "&Tools"
msgstr "&Herramientas"
msgid "&Settings"
msgstr "&Preferencias"
msgid "Back"
msgstr "Atrás"
msgid "Close"
msgstr "Cerrar"
msgid "&Apply"
msgstr "&Aplicar"
msgid "&Cancel"
msgstr "&Cancelar"
msgid "&Close"
msgstr "&Cerrar"
msgid "Error"
msgstr "Error"
msgid "&Open"
msgstr "&Abrir"
msgid "Save"
msgstr "Guardar"
msgid "&Yes"
msgstr "&Sí"
msgid "&No"
msgstr "&No"
msgid "Yes"
msgstr "Sí"
msgid "No"
msgstr "No"
/**
* \file flacfile.cpp
* Handling of FLAC files.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 04 Oct 2005
*/
#include "flacfile.h"
#ifdef HAVE_FLAC
#include "standardtags.h"
#include "genres.h"
#include "flacframelist.h"
#include <FLAC++/metadata.h>
#include <qfile.h>
#include <qdir.h>
#include <sys/stat.h>
#ifdef WIN32
#include <sys/utime.h>
#else
#include <utime.h>
#endif
#include <cstdio>
#include <cmath>
/**
* Constructor.
*
* @param dn directory name
* @param fn filename
*/
FlacFile::FlacFile(const QString& dn, const QString& fn) :
OggFile(dn, fn), m_chain(0)
{
}
/**
* Destructor.
*/
FlacFile::~FlacFile()
{
if (m_chain) {
delete m_chain;
}
}
/**
* Read tags from file.
*
* @param force true to force reading even if tags were already read.
*/
void FlacFile::readTags(bool force)
{
if (force || !m_fileRead) {
m_comments.clear();
changedV2 = false;
m_fileRead = true;
QCString fnIn = QFile::encodeName(dirname + QDir::separator() + filename);
m_fileInfo.read(0); // just to start invalid
if (!m_chain) {
m_chain = new FLAC::Metadata::Chain;
}
if (m_chain && m_chain->is_valid()) {
if (m_chain->read(fnIn)) {
FLAC::Metadata::Iterator* mdit = new FLAC::Metadata::Iterator;
if (mdit) {
mdit->init(*m_chain);
while (mdit->is_valid()) {
::FLAC__MetadataType mdt = mdit->get_block_type();
if (mdt == FLAC__METADATA_TYPE_STREAMINFO) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::StreamInfo* si =
dynamic_cast<FLAC::Metadata::StreamInfo*>(proto);
m_fileInfo.read(si);
delete proto;
}
} else if (mdt == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
FLAC::Metadata::Prototype* proto = mdit->get_block();
if (proto) {
FLAC::Metadata::VorbisComment* vc =
dynamic_cast<FLAC::Metadata::VorbisComment*>(proto);
if (vc && vc->is_valid()) {
unsigned numComments = vc->get_num_comments();
for (unsigned i = 0; i < numComments; ++i) {
FLAC::Metadata::VorbisComment::Entry entry =
vc->get_comment(i);
if (entry.is_valid()) {
QString name =
QString::fromUtf8(entry.get_field_name(),
entry.get_field_name_length()).
stripWhiteSpace().upper();
QString value =
QString::fromUtf8(entry.get_field_value(),
entry.get_field_value_length()).
stripWhiteSpace();
if (!value.isEmpty()) {
#if QT_VERSION >= 300
m_comments.push_back(
CommentField(name, value));
#else
m_comments.append(
CommentField(name, value));
#endif
}
}
}
}
delete proto;
}
}
if (!mdit->next()) {
break;
}
}
delete mdit;
}
}
}
}
if (force) {
new_filename = filename;
}
}
/**
* Write tags to file and rename it if necessary.
*
* @param force true to force writing even if file was not changed.
* @param renamed will be set to true if the file was renamed,
* i.e. the file name is no longer valid, else *renamed
* is left unchanged