Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions libdiodon/file-clipboard-item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace Diodon
*/
private string _paths;
private string? _origin;
private string _label;
private string _checksum;
private ClipboardType _clipboard_type;
private DateTime _date_copied;

Expand All @@ -52,6 +54,7 @@ namespace Diodon
_paths = data;
_origin = origin;
_date_copied = date_copied;
_checksum = Checksum.compute_for_string(ChecksumType.SHA1, _paths);

// check if all paths are available
string[] paths = convert_to_paths(_paths);
Expand All @@ -61,6 +64,21 @@ namespace Diodon
throw new FileError.NOENT("No such file or directory " + path);
}
}

// label should not be longer than 50
string home = Environment.get_home_dir();
_label = "";
foreach(string p in paths) {
if(_label.length > 0) {
_label += " ";
}
_label += p.replace(home, "~");

if (_label.char_count() > 50) {
_label = _label.substring(0, 50) + "...";
break;
}
}
}

/**
Expand Down Expand Up @@ -100,20 +118,7 @@ namespace Diodon
*/
public string get_label()
{
string home = Environment.get_home_dir();

// label should not be longer than 50 letters
string label = _paths.replace("\n", " ");

// replacing home dir with common known tilde
label = label.replace(home, "~");

if (label.char_count() > 50) {
long index_char = label.index_of_nth_char(50);
label = label.substring(0, index_char) + "...";
}

return label;
return _label;
}

/**
Expand Down Expand Up @@ -196,7 +201,7 @@ namespace Diodon
*/
public string get_checksum()
{
return Checksum.compute_for_string(ChecksumType.SHA1, _paths);
return _checksum;
}

/**
Expand Down
21 changes: 12 additions & 9 deletions libdiodon/text-clipboard-item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Diodon
{
private string _text;
private string? _origin;
private string _label;
private string _checksum;
private ClipboardType _clipboard_type;
private DateTime _date_copied;

Expand All @@ -44,6 +46,14 @@ namespace Diodon
_text = data;
_origin = origin;
_date_copied = date_copied;
_checksum = Checksum.compute_for_string(ChecksumType.SHA1, _text);

// label should not be longer than 50 letters
_label = _text;
if (_label.char_count() > 50) {
_label = _label.substring(0, 50) + "...";
}
_label = _label.replace("\n", " ");
}

/**
Expand Down Expand Up @@ -83,14 +93,7 @@ namespace Diodon
*/
public string get_label()
{
// label should not be longer than 50 letters
string label = _text.replace("\n", " ");
if (label.char_count() > 50) {
long index_char = label.index_of_nth_char(50);
label = label.substring(0, index_char) + "...";
}

return label;
return _label;
}

/**
Expand Down Expand Up @@ -138,7 +141,7 @@ namespace Diodon
*/
public string get_checksum()
{
return Checksum.compute_for_string(ChecksumType.SHA1, _text);
return _checksum;
}

/**
Expand Down