Skip to content

Commit

Permalink
edit title & short text
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Ehrnsperger committed Jan 14, 2024
1 parent af40f42 commit 7649dae
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
4 changes: 2 additions & 2 deletions live/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ form {
padding: 0;
}

input {
input, textarea {
border: 1px solid #6D96A9;
font-size: 11px;
font-family: Verdana, Arial, Helvetica, sans-serif;
background: #FEFEFE;
margin: 0;
}
input.width99 {
input.width99, textarea.width99 {
width: 99%;
}

Expand Down
42 changes: 17 additions & 25 deletions pages/edit_recording.ecpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%pre>

#include <tools.h>
#include <recman.h>
#include <setup.h>
#include <users.h>
Expand All @@ -20,6 +19,9 @@ using namespace vdrlive;
std::string name = "";
std::string directory = "";
std::string newdir = "";
std::string title = "";
std::string shorttext = "";
std::string description = "";
std::string delresume = "";
std::string delmarks = "";
std::string copy = "";
Expand Down Expand Up @@ -63,8 +65,7 @@ const cRecording* recording;
if (delmarks == "delmarks") LiveRecordingsManager()->DeleteMarks(recording);
if (copy == "copy") copy_only = true;
if (newdir != ".") directory = newdir;
std::string filename = directory.empty() ? name : StringReplace(directory, "/", "~") + "~" + name;
if (LiveRecordingsManager()->MoveRecording(recording, FileSystemExchangeChars(filename, true), copy_only))
if (LiveRecordingsManager()->UpdateRecording(recording, directory, name, copy_only, title, shorttext, description))
returnToReferer = true;
else
message = tr("Cannot copy, rename or move the recording.");
Expand All @@ -83,17 +84,12 @@ const cRecording* recording;
} else {

if (recording) {
std::string path = recording->Name();
size_t found = path.find_last_of("~");

if (found != std::string::npos) {
directory = StringReplace(path.substr(0, found), "~", "/");
name = path.substr(found + 1);
}
else {
directory = "";
name = path;
}
cRecordingInfo *info = recording->Info();
name = recording->BaseName();
directory = StringReplace(*recording->Folder(), "~", "/");
title = cSv(info->Title());
shorttext = cSv(info->ShortText());
description = cSv(info->Description());
}
</%cpp>
<& pageelems.doc_type &>
Expand Down Expand Up @@ -155,7 +151,7 @@ const cRecording* recording;
}
</%cpp>
</select>
<img id="new_dir_button" class="icon" src="<$ LiveSetup().GetThemedLink("img", "button_new.png") $>" title="<$tr("Create new directory")$>" onclick="new_dir()" style="vertical-align: middle">
<img id="new_dir_button" class="icon" src="<$ LiveSetup().GetThemedLink("img", "button_new.png") $>" title="<$tr("Create new directory")$>" onclick="new_dir()" style="vertical-align: middle">
<input type="text" name="newdir" id="newdir" value="." size="55" class="width99" style="display:none" />
</td>
</tr>
Expand All @@ -171,24 +167,20 @@ const cRecording* recording;
<td class="label leftcol"><div class="withmargin"><$ tr("Copy only") $>:</div></td>
<td class="rightcol"><input type="checkbox" name="copy" value="copy"/></td>
</tr>
<%cpp>
if (recording && recording->Info()->ShortText()) {
</%cpp>
<tr>
<td class="label leftcol"><div class="withmargin"><$ tr("Title") $>:</div></td>
<td class="rightcol"><input type="text" name="title" value="<$ title $>" size="55" class="width99" /></td>
</tr>
<tr>
<td class="label leftcol"><div class="withmargin"><$ tr("Short description") $>:</div></td>
<td class="rightcol"><$ recording->Info()->ShortText() $></td>
<td class="rightcol"><input type="text" name="shorttext" value="<$ shorttext $>" size="55" class="width99" /></td>
</tr>
<%cpp>
}
if (recording && recording->Info()->Description()) {
</%cpp>
<tr>
<td class="label leftcol"><div class="withmargin"><$ tr("Description") $>:</div></td>
<td class="rightcol"><$ recording->Info()->Description() $></td>
<td class="rightcol"><textarea name="description" rows="8" cols="55" class="width99"><$ description $></textarea></td>
</tr>
<%cpp>

}
if (recording && recording->Info()->Aux()) {
std::string aux_data;
cGetAutoTimerReason getAutoTimerReason;
Expand Down
30 changes: 22 additions & 8 deletions recman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,26 @@ template void StringAppendFrameParams<cToSvConcat<255>>(cToSvConcat<255> &s, con
return 0;
}

bool RecordingsManager::MoveRecording(cRecording const * recording, cSv name, bool copy) const
bool RecordingsManager::UpdateRecording(cRecording const * recording, cSv directory, cSv name, bool copy, cSv title, cSv shorttext, cSv description) const
{
if (!recording)
return false;

// Check for injections that try to escape from the video dir.
if (name.compare(0, 3, "../") == 0 || name.find("/..") != std::string::npos) {
esyslog("live: renaming failed: new name invalid \"%.*s\"", (int)name.length(), name.data());
return false;
}

std::string oldname = recording->FileName();
size_t found = oldname.find_last_of("/");

if (found == std::string::npos)
return false;

std::string newname = concat(cVideoDirectory::Name(), "/", name, cSv(oldname).substr(found));
std::string filename = FileSystemExchangeChars(directory.empty() ? name : (StringReplace(directory, "/", "~") + "~").append(name), true);

// Check for injections that try to escape from the video dir.
if (filename.compare(0, 3, "..~") == 0 || filename.find("~..") != std::string::npos) {
esyslog("live: renaming failed: new name invalid \"%.*s\"", (int)filename.length(), filename.data());
return false;
}

std::string newname = concat(cVideoDirectory::Name(), "/", filename, cSv(oldname).substr(found));

if (!MoveDirectory(oldname, newname, copy)) {
esyslog("live: renaming failed from '%.*s' to '%s'", (int)oldname.length(), oldname.data(), newname.c_str());
Expand All @@ -132,6 +134,18 @@ template void StringAppendFrameParams<cToSvConcat<255>>(cToSvConcat<255> &s, con
Recordings->AddByName(newname.c_str());
cRecordingUserCommand::InvokeCommand(*cString::sprintf("rename \"%s\"", *strescape(oldname.c_str(), "\\\"$'")), newname.c_str());

// update texts
// need null terminated strings for VDR API
std::string desc(description);
desc.erase(std::remove(desc.begin(), desc.end(), '\r'), desc.end()); // remove \r from HTML

cRecordingInfo* info = recording->Info();
if (title != cSv(info->Title()) || shorttext != cSv(info->ShortText()) || desc != cSv(info->Description()))
{
info->SetData(title.empty() ? nullptr : std::string(title).c_str(), shorttext.empty() ? nullptr : std::string(shorttext).c_str(), desc.empty() ? nullptr : desc.c_str());
info->Write();
}

return true;
}

Expand Down
8 changes: 7 additions & 1 deletion recman.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ template<typename T>
/**
* Move a recording with the given hash according to
* VDRs recording mechanisms.
* @param directory new name of the sub folder this recording is stored in.
* @param name new recording folder name.
* @param copy create a copy of the original recording rather than moving it.
* @param title new title of the recording.
* @param shorttext new short text of the recording.
* @param description new description of the recording.
*/
bool MoveRecording(cRecording const * recording, cSv name, bool copy = false) const;
bool UpdateRecording(cRecording const * recording, cSv directory, cSv name, bool copy, cSv title, cSv shorttext, cSv description) const;

/**
* Delete recording resume with the given hash according to
Expand Down

0 comments on commit 7649dae

Please sign in to comment.