move some functions to TagEditor class / outside
This commit is contained in:
@@ -239,6 +239,35 @@ bool Keypressed(int in, const int *key)
|
|||||||
return in == key[0] || in == key[1];
|
return in == key[0] || in == key[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
string FindSharedDir(Menu<Song> *menu)
|
||||||
|
{
|
||||||
|
SongList list;
|
||||||
|
for (size_t i = 0; i < menu->Size(); i++)
|
||||||
|
list.push_back(&menu->at(i));
|
||||||
|
return FindSharedDir(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
string FindSharedDir(const SongList &v)
|
||||||
|
{
|
||||||
|
string result;
|
||||||
|
if (!v.empty())
|
||||||
|
{
|
||||||
|
result = v.front()->GetFile();
|
||||||
|
for (SongList::const_iterator it = v.begin()+1; it != v.end(); it++)
|
||||||
|
{
|
||||||
|
int i = 1;
|
||||||
|
while (result.substr(0, i) == (*it)->GetFile().substr(0, i))
|
||||||
|
i++;
|
||||||
|
result = result.substr(0, i);
|
||||||
|
}
|
||||||
|
size_t slash = result.rfind("/");
|
||||||
|
result = slash != string::npos ? result.substr(0, slash) : "/";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
string FindSharedDir(const string &one, const string &two)
|
string FindSharedDir(const string &one, const string &two)
|
||||||
{
|
{
|
||||||
if (one == two)
|
if (one == two)
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ void UpdateSongList(Menu<MPD::Song> *);
|
|||||||
|
|
||||||
bool Keypressed(int, const int *);
|
bool Keypressed(int, const int *);
|
||||||
|
|
||||||
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
std::string FindSharedDir(Menu<MPD::Song> *);
|
||||||
|
std::string FindSharedDir(const MPD::SongList &);
|
||||||
|
#endif // HAVE_TAGLIB_H
|
||||||
std::string FindSharedDir(const std::string &, const std::string &);
|
std::string FindSharedDir(const std::string &, const std::string &);
|
||||||
|
|
||||||
std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
|
std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
|
||||||
|
|||||||
33
src/misc.cpp
33
src/misc.cpp
@@ -145,6 +145,39 @@ mpd_TagItems IntoTagItem(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
MPD::Song::SetFunction IntoSetFunction(mpd_TagItems tag)
|
||||||
|
{
|
||||||
|
switch (tag)
|
||||||
|
{
|
||||||
|
case MPD_TAG_ITEM_ARTIST:
|
||||||
|
return &MPD::Song::SetArtist;
|
||||||
|
case MPD_TAG_ITEM_ALBUM:
|
||||||
|
return &MPD::Song::SetAlbum;
|
||||||
|
case MPD_TAG_ITEM_TITLE:
|
||||||
|
return &MPD::Song::SetTitle;
|
||||||
|
case MPD_TAG_ITEM_TRACK:
|
||||||
|
return &MPD::Song::SetTrack;
|
||||||
|
case MPD_TAG_ITEM_GENRE:
|
||||||
|
return &MPD::Song::SetGenre;
|
||||||
|
case MPD_TAG_ITEM_DATE:
|
||||||
|
return &MPD::Song::SetYear;
|
||||||
|
case MPD_TAG_ITEM_COMPOSER:
|
||||||
|
return &MPD::Song::SetComposer;
|
||||||
|
case MPD_TAG_ITEM_PERFORMER:
|
||||||
|
return &MPD::Song::SetPerformer;
|
||||||
|
case MPD_TAG_ITEM_COMMENT:
|
||||||
|
return &MPD::Song::SetComment;
|
||||||
|
case MPD_TAG_ITEM_DISC:
|
||||||
|
return &MPD::Song::SetDisc;
|
||||||
|
case MPD_TAG_ITEM_FILENAME:
|
||||||
|
return &MPD::Song::SetNewName;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
void EscapeUnallowedChars(std::string &s)
|
void EscapeUnallowedChars(std::string &s)
|
||||||
{
|
{
|
||||||
for (std::string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
for (std::string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "libmpdclient.h"
|
#include "song.h"
|
||||||
|
|
||||||
void ToLower(std::string &);
|
void ToLower(std::string &);
|
||||||
|
|
||||||
@@ -40,6 +40,10 @@ Color IntoColor(const std::string &);
|
|||||||
|
|
||||||
mpd_TagItems IntoTagItem(char);
|
mpd_TagItems IntoTagItem(char);
|
||||||
|
|
||||||
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
MPD::Song::SetFunction IntoSetFunction(mpd_TagItems);
|
||||||
|
#endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
void EscapeUnallowedChars(std::string &);
|
void EscapeUnallowedChars(std::string &);
|
||||||
|
|
||||||
void EscapeHtml(std::string &s);
|
void EscapeHtml(std::string &s);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "charset.h"
|
#include "charset.h"
|
||||||
|
#include "misc.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
using MPD::Song;
|
using MPD::Song;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "misc.h"
|
|
||||||
#include "libmpdclient.h"
|
#include "libmpdclient.h"
|
||||||
|
|
||||||
namespace MPD
|
namespace MPD
|
||||||
|
|||||||
@@ -287,6 +287,9 @@ bool TinyTagEditor::GetTags()
|
|||||||
|
|
||||||
TagEditor *myTagEditor = new TagEditor;
|
TagEditor *myTagEditor = new TagEditor;
|
||||||
|
|
||||||
|
const string TagEditor::PatternsFile = config_dir + "patterns.list";
|
||||||
|
vector<string> TagEditor::Patterns;
|
||||||
|
|
||||||
const size_t TagEditor::MiddleColumnWidth = 26;
|
const size_t TagEditor::MiddleColumnWidth = 26;
|
||||||
size_t TagEditor::LeftColumnWidth;
|
size_t TagEditor::LeftColumnWidth;
|
||||||
size_t TagEditor::MiddleColumnStartX;
|
size_t TagEditor::MiddleColumnStartX;
|
||||||
@@ -1046,41 +1049,36 @@ std::string TagEditor::TagToString(const MPD::Song &s, void *data)
|
|||||||
return result.empty() ? Config.empty_tag : result;
|
return result.empty() ? Config.empty_tag : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
void TagEditor::GetPatternList()
|
||||||
{
|
{
|
||||||
const string patterns_list_file = config_dir + "patterns.list";
|
if (Patterns.empty())
|
||||||
vector<string> patterns_list;
|
|
||||||
|
|
||||||
void GetPatternList()
|
|
||||||
{
|
{
|
||||||
if (patterns_list.empty())
|
std::ifstream input(PatternsFile.c_str());
|
||||||
{
|
|
||||||
std::ifstream input(patterns_list_file.c_str());
|
|
||||||
if (input.is_open())
|
if (input.is_open())
|
||||||
{
|
{
|
||||||
string line;
|
string line;
|
||||||
while (getline(input, line))
|
while (getline(input, line))
|
||||||
{
|
{
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
patterns_list.push_back(line);
|
Patterns.push_back(line);
|
||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavePatternList()
|
void TagEditor::SavePatternList()
|
||||||
{
|
{
|
||||||
std::ofstream output(patterns_list_file.c_str());
|
std::ofstream output(PatternsFile.c_str());
|
||||||
if (output.is_open())
|
if (output.is_open())
|
||||||
{
|
{
|
||||||
for (vector<string>::const_iterator it = patterns_list.begin(); it != patterns_list.end() && it != patterns_list.begin()+30; it++)
|
for (vector<string>::const_iterator it = Patterns.begin(); it != Patterns.end() && it != Patterns.begin()+30; it++)
|
||||||
output << *it << std::endl;
|
output << *it << std::endl;
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Song::SetFunction IntoSetFunction(char c)
|
Song::SetFunction TagEditor::IntoSetFunction(char c)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@@ -1109,14 +1107,14 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string GenerateFilename(const Song &s, string &pattern)
|
string TagEditor::GenerateFilename(const Song &s, string &pattern)
|
||||||
{
|
{
|
||||||
string result = s.toString(pattern);
|
string result = s.toString(pattern);
|
||||||
EscapeUnallowedChars(result);
|
EscapeUnallowedChars(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ParseFilename(Song &s, string mask, bool preview)
|
string TagEditor::ParseFilename(Song &s, string mask, bool preview)
|
||||||
{
|
{
|
||||||
std::ostringstream result;
|
std::ostringstream result;
|
||||||
vector<string> separators;
|
vector<string> separators;
|
||||||
@@ -1165,67 +1163,8 @@ namespace
|
|||||||
}
|
}
|
||||||
return result.str();
|
return result.str();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Song::SetFunction IntoSetFunction(mpd_TagItems tag)
|
void TagEditor::DealWithFilenames(SongList &v)
|
||||||
{
|
|
||||||
switch (tag)
|
|
||||||
{
|
|
||||||
case MPD_TAG_ITEM_ARTIST:
|
|
||||||
return &Song::SetArtist;
|
|
||||||
case MPD_TAG_ITEM_ALBUM:
|
|
||||||
return &Song::SetAlbum;
|
|
||||||
case MPD_TAG_ITEM_TITLE:
|
|
||||||
return &Song::SetTitle;
|
|
||||||
case MPD_TAG_ITEM_TRACK:
|
|
||||||
return &Song::SetTrack;
|
|
||||||
case MPD_TAG_ITEM_GENRE:
|
|
||||||
return &Song::SetGenre;
|
|
||||||
case MPD_TAG_ITEM_DATE:
|
|
||||||
return &Song::SetYear;
|
|
||||||
case MPD_TAG_ITEM_COMPOSER:
|
|
||||||
return &Song::SetComposer;
|
|
||||||
case MPD_TAG_ITEM_PERFORMER:
|
|
||||||
return &Song::SetPerformer;
|
|
||||||
case MPD_TAG_ITEM_COMMENT:
|
|
||||||
return &Song::SetComment;
|
|
||||||
case MPD_TAG_ITEM_DISC:
|
|
||||||
return &Song::SetDisc;
|
|
||||||
case MPD_TAG_ITEM_FILENAME:
|
|
||||||
return &Song::SetNewName;
|
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string FindSharedDir(Menu<Song> *menu)
|
|
||||||
{
|
|
||||||
SongList list;
|
|
||||||
for (size_t i = 0; i < menu->Size(); i++)
|
|
||||||
list.push_back(&menu->at(i));
|
|
||||||
return FindSharedDir(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
string FindSharedDir(const SongList &v)
|
|
||||||
{
|
|
||||||
string result;
|
|
||||||
if (!v.empty())
|
|
||||||
{
|
|
||||||
result = v.front()->GetFile();
|
|
||||||
for (SongList::const_iterator it = v.begin()+1; it != v.end(); it++)
|
|
||||||
{
|
|
||||||
int i = 1;
|
|
||||||
while (result.substr(0, i) == (*it)->GetFile().substr(0, i))
|
|
||||||
i++;
|
|
||||||
result = result.substr(0, i);
|
|
||||||
}
|
|
||||||
size_t slash = result.rfind("/");
|
|
||||||
result = slash != string::npos ? result.substr(0, slash) : "/";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DealWithFilenames(SongList &v)
|
|
||||||
{
|
{
|
||||||
int width = 30;
|
int width = 30;
|
||||||
int height = 6;
|
int height = 6;
|
||||||
@@ -1296,20 +1235,20 @@ void DealWithFilenames(SongList &v)
|
|||||||
Main->SetTimeout(ncmpcpp_window_timeout);
|
Main->SetTimeout(ncmpcpp_window_timeout);
|
||||||
Main->SetItemDisplayer(Display::Generic);
|
Main->SetItemDisplayer(Display::Generic);
|
||||||
|
|
||||||
if (!patterns_list.empty())
|
if (!Patterns.empty())
|
||||||
Config.pattern = patterns_list.front();
|
Config.pattern = Patterns.front();
|
||||||
Main->AddOption("Pattern: " + Config.pattern);
|
Main->AddOption("Pattern: " + Config.pattern);
|
||||||
Main->AddOption("Preview");
|
Main->AddOption("Preview");
|
||||||
Main->AddOption("Legend");
|
Main->AddOption("Legend");
|
||||||
Main->AddSeparator();
|
Main->AddSeparator();
|
||||||
Main->AddOption("Proceed");
|
Main->AddOption("Proceed");
|
||||||
Main->AddOption("Cancel");
|
Main->AddOption("Cancel");
|
||||||
if (!patterns_list.empty())
|
if (!Patterns.empty())
|
||||||
{
|
{
|
||||||
Main->AddSeparator();
|
Main->AddSeparator();
|
||||||
Main->AddOption("Recent patterns", 1, 1);
|
Main->AddOption("Recent patterns", 1, 1);
|
||||||
Main->AddSeparator();
|
Main->AddSeparator();
|
||||||
for (vector<string>::const_iterator it = patterns_list.begin(); it != patterns_list.end(); it++)
|
for (vector<string>::const_iterator it = Patterns.begin(); it != Patterns.end(); it++)
|
||||||
Main->AddOption(*it);
|
Main->AddOption(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1406,15 +1345,15 @@ void DealWithFilenames(SongList &v)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < patterns_list.size(); i++)
|
for (size_t i = 0; i < Patterns.size(); i++)
|
||||||
{
|
{
|
||||||
if (patterns_list[i] == Config.pattern)
|
if (Patterns[i] == Config.pattern)
|
||||||
{
|
{
|
||||||
patterns_list.erase(patterns_list.begin()+i);
|
Patterns.erase(Patterns.begin()+i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
patterns_list.insert(patterns_list.begin(), Config.pattern);
|
Patterns.insert(Patterns.begin(), Config.pattern);
|
||||||
}
|
}
|
||||||
ShowMessage("Operation finished!");
|
ShowMessage("Operation finished!");
|
||||||
if (preview)
|
if (preview)
|
||||||
|
|||||||
@@ -105,11 +105,22 @@ class TagEditor : public Screen<Window>
|
|||||||
static void LowerAllLetters(MPD::Song &);
|
static void LowerAllLetters(MPD::Song &);
|
||||||
static void GetTagList(TagLib::StringList &, const std::string &);
|
static void GetTagList(TagLib::StringList &, const std::string &);
|
||||||
|
|
||||||
|
static void GetPatternList();
|
||||||
|
static void SavePatternList();
|
||||||
|
static MPD::Song::SetFunction IntoSetFunction(char);
|
||||||
|
static std::string GenerateFilename(const MPD::Song &, std::string &);
|
||||||
|
static std::string ParseFilename(MPD::Song &, std::string, bool);
|
||||||
|
|
||||||
|
static void DealWithFilenames(MPD::SongList &);
|
||||||
|
|
||||||
static std::string TagToString(const MPD::Song &, void *);
|
static std::string TagToString(const MPD::Song &, void *);
|
||||||
|
|
||||||
std::string itsBrowsedDir;
|
std::string itsBrowsedDir;
|
||||||
std::string itsHighlightedDir;
|
std::string itsHighlightedDir;
|
||||||
|
|
||||||
|
static const std::string PatternsFile;
|
||||||
|
static std::vector<std::string> Patterns;
|
||||||
|
|
||||||
static const size_t MiddleColumnWidth;
|
static const size_t MiddleColumnWidth;
|
||||||
static size_t LeftColumnWidth;
|
static size_t LeftColumnWidth;
|
||||||
static size_t MiddleColumnStartX;
|
static size_t MiddleColumnStartX;
|
||||||
@@ -119,13 +130,6 @@ class TagEditor : public Screen<Window>
|
|||||||
|
|
||||||
extern TagEditor *myTagEditor;
|
extern TagEditor *myTagEditor;
|
||||||
|
|
||||||
std::string FindSharedDir(Menu<MPD::Song> *);
|
|
||||||
std::string FindSharedDir(const MPD::SongList &);
|
|
||||||
|
|
||||||
MPD::Song::SetFunction IntoSetFunction(mpd_TagItems);
|
|
||||||
|
|
||||||
void DealWithFilenames(MPD::SongList &);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user