Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/logdata/include/compressedlinestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class CompressedLinePositionStorage {
// Cache the last position read
// This is to speed up consecutive reads (whole page)
struct Cache {
LineNumber index {std::numeric_limits<LineNumber::UnderlyingType>::max() - 1U};
static constexpr auto i = std::numeric_limits<LineNumber::UnderlyingType>::max() - 1U;
LineNumber index {i};
LineOffset position {0};
BlockOffset offset {0};
};
Expand Down
3 changes: 2 additions & 1 deletion src/logdata/include/logfiltereddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class LogFilteredData : public AbstractLogData {
// Nothing is done if no search is in progress.
void interruptSearch();
// Clear the search and the list of results.
void clearSearch( bool dropCache = false );
template <bool dropCache = false>
void clearSearch();

// Returns the line number in the original LogData where the element
// 'index' was found.
Expand Down
5 changes: 3 additions & 2 deletions src/logdata/src/logfiltereddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void LogFilteredData::interruptSearch()
workerThread_.interrupt();
}

void LogFilteredData::clearSearch( bool dropCache )
template <bool dropCache>
void LogFilteredData::clearSearch()
{
interruptSearch();

Expand All @@ -160,7 +161,7 @@ void LogFilteredData::clearSearch( bool dropCache )
maxLength_ = 0_length;
nbLinesProcessed_ = 0_lcount;

if ( dropCache ) {
if constexpr ( dropCache ) {
searchResultsCache_.clear();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class MainWindow : public QMainWindow {
void logScreenInfo( QScreen* screen );
void removeFromFavorites( const QString& pathToRemove );
void removeFromRecent( const QString& pathToRemove );
void tryOpenClipboard( int tryTimes );
template<int tryTimes>
void tryOpenClipboard();
void updateShortcuts();

WindowSession session_;
Expand Down
7 changes: 4 additions & 3 deletions src/ui/src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void CrawlerWidget::reload()
{
searchState_.resetState();
constexpr auto DropCache = true;
logFilteredData_->clearSearch( DropCache );
logFilteredData_->clearSearch< DropCache >();
logFilteredData_->clearMarks();
filteredView_->updateData();
printSearchInfoMessage();
Expand Down Expand Up @@ -698,7 +698,7 @@ void CrawlerWidget::fileChangedHandler( MonitoredFileStatus status )
if ( !searchInfoLine_->text().isEmpty() ) {
// Invalidate the search
constexpr auto DropCache = true;
logFilteredData_->clearSearch( DropCache );
logFilteredData_->clearSearch< DropCache >();
filteredView_->updateData();
searchState_.truncateFile();
printSearchInfoMessage();
Expand Down Expand Up @@ -1033,7 +1033,8 @@ void CrawlerWidget::setup()
searchLineEdit_->addItems( savedSearches_->recentSearches() );
searchLineEdit_->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
searchLineEdit_->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLengthWithIcon );
searchLineEdit_->lineEdit()->setMaxLength( std::numeric_limits<int>::max() / 1024 );
constexpr auto maxLength = std::numeric_limits<int>::max() / 1024;
searchLineEdit_->lineEdit()->setMaxLength( maxLength );
searchLineEdit_->setContentsMargins( 2, 2, 2, 2 );

QAction* clearSearchHistoryAction = new QAction( "Clear search history", this );
Expand Down
18 changes: 12 additions & 6 deletions src/ui/src/displayfilepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@
constexpr const int MaxPathLength = 128;
namespace {
// inspired by http://chadkuehn.com/shrink-file-paths-with-an-ellipsis-in-c/
QString shrinkPath( QString fullPath, int limit, QString delimiter = "…" )
template <int limit>
QString shrinkPath( const QString& fullPath )
{
if ( fullPath.isEmpty() ) {
return fullPath;
}

constexpr const auto delimiter = "…";
constexpr auto delimiterLen =
static_cast<qsizetype>( std::char_traits<char>::length( delimiter ) );

const auto fileInfo = QFileInfo( fullPath );
const auto fileName = fileInfo.fileName();
const auto absoluteNativePath = QDir::toNativeSeparators( fileInfo.absolutePath() );

const auto idealMinLength = fileName.length() + delimiter.length();
const auto idealMinLength = fileName.length() + delimiterLen;

// less than the minimum amt
if ( limit < ( ( 2 * delimiter.length() ) + 1 ) ) {
if constexpr ( limit < ( ( 2 * delimiterLen ) + 1 ) ) {
return "";
}

Expand All @@ -48,15 +53,16 @@ QString shrinkPath( QString fullPath, int limit, QString delimiter = "…" )

// file name condensing
if ( limit < idealMinLength ) {
return delimiter + fileName.mid( 0, ( limit - ( 2 * delimiter.length() ) ) ) + delimiter;
constexpr auto n = ( limit - ( 2 * delimiterLen ) );
return delimiter + fileName.mid( 0, n ) + delimiter;
}

// whole name only, no folder structure shown
if ( limit == idealMinLength ) {
return delimiter + fileName;
}

return absoluteNativePath.mid( 0, ( limit - ( idealMinLength + 1 ) ) ) + delimiter
return absoluteNativePath.mid( 0, ( static_cast<qsizetype>( limit ) - ( idealMinLength + 1 ) ) ) + delimiter
+ QDir::separator() + fileName;
}

Expand All @@ -65,7 +71,7 @@ QString shrinkPath( QString fullPath, int limit, QString delimiter = "…" )
DisplayFilePath::DisplayFilePath( const QString& fullPath )
: fullPath_( fullPath )
, nativeFullPath_( QDir::toNativeSeparators( fullPath ) )
, displayName_( shrinkPath( fullPath, MaxPathLength ) )
, displayName_( shrinkPath<MaxPathLength>( fullPath ) )
{
}

Expand Down
25 changes: 14 additions & 11 deletions src/ui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,28 +915,31 @@ void MainWindow::openInEditor()
openFileInDefaultApplication( session_.getFilename( currentCrawlerWidget() ) );
}

void MainWindow::tryOpenClipboard( int tryTimes )
template <int tryTimes>
void MainWindow::tryOpenClipboard()
{
auto clipboard = QGuiApplication::clipboard();
auto text = clipboard->text();

if ( text.isEmpty() && tryTimes > 0 ) {
QTimer::singleShot( 50, [ tryTimes, this ]() { tryOpenClipboard( tryTimes - 1 ); } );
}
else {
auto tempFile = new QTemporaryFile( tempDir_.filePath( "klogg_clipboard" ), this );
if ( tempFile->open() ) {
tempFile->write( text.toUtf8() );
tempFile->flush();
if constexpr ( tryTimes > 0 ) {
if ( text.isEmpty() ) {
QTimer::singleShot( 50, [ this ]() { tryOpenClipboard< tryTimes - 1 >(); } );
}
else {
auto tempFile = new QTemporaryFile( tempDir_.filePath( "klogg_clipboard" ), this );
if ( tempFile->open() ) {
tempFile->write( text.toUtf8() );
tempFile->flush();

loadFile( tempFile->fileName() );
loadFile( tempFile->fileName() );
}
}
}
}

void MainWindow::openClipboard()
{
tryOpenClipboard( ClipboardMaxTry );
tryOpenClipboard< ClipboardMaxTry >();
}

void MainWindow::openUrl()
Expand Down