Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Abs62/goldendict
base: 81ee55aff7
...
head fork: Abs62/goldendict
compare: 11561ac4af
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 11 files changed
  • 0 commit comments
  • 3 contributors
Commits on Jan 26, 2012
vtliem Fix wiki url
1/ audio url in a tag (<a href="//upload.....org)
2/File:xxx.xxx link @goldendict#61
10a5655
Commits on Feb 13, 2012
@Abs62 Add missing header to decompress.cc d4d9ab4
Commits on Feb 15, 2012
@dragonroot dragonroot Merge pull request #77 from thanhliem/master
Fix wiki url
03d1dfe
@Abs62 Avoid bug with tabs in Qt 4.8.0 a06df0a
Commits on Feb 16, 2012
@Abs62 Large search history 11561ac
View
10 config.cc
@@ -121,7 +121,8 @@ Preferences::Preferences():
disallowContentFromOtherSites( false ),
enableWebPlugins( false ),
zoomFactor( 1 ),
- wordsZoomLevel( 0 )
+ wordsZoomLevel( 0 ),
+ maxStringsInHistory( 500 )
{
}
@@ -642,6 +643,9 @@ Class load() throw( exError )
if ( !preferences.namedItem( "enableWebPlugins" ).isNull() )
c.preferences.enableWebPlugins = ( preferences.namedItem( "enableWebPlugins" ).toElement().text() == "1" );
+
+ if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() )
+ c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ;
}
c.lastMainGroupId = root.namedItem( "lastMainGroupId" ).toElement().text().toUInt();
@@ -1192,6 +1196,10 @@ void save( Class const & c ) throw( exError )
opt = dd.createElement( "enableWebPlugins" );
opt.appendChild( dd.createTextNode( c.preferences.enableWebPlugins ? "1" : "0" ) );
preferences.appendChild( opt );
+
+ opt = dd.createElement( "maxStringsInHistory" );
+ opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
+ preferences.appendChild( opt );
}
{
View
2  config.hh
@@ -179,6 +179,8 @@ struct Preferences
qreal zoomFactor;
int wordsZoomLevel;
+ unsigned maxStringsInHistory;
+
Preferences();
};
View
2  decompress.cc
@@ -1,4 +1,4 @@
-#include <stdlib.h>
+#include <string.h>
#include "decompress.hh"
#include "zlib.h"
View
9 history.cc
@@ -6,11 +6,13 @@
#include "atomic_rename.hh"
#include <QFile>
-History::History( unsigned size ): maxSize( size )
+History::History( unsigned size ): maxSize( size ),
+addingEnabled( true )
{
}
-History::History( Load, unsigned size ): maxSize( size )
+History::History( Load, unsigned size ): maxSize( size ),
+addingEnabled( true )
{
QFile file( Config::getHistoryFileName() );
@@ -48,6 +50,9 @@ History::History( Load, unsigned size ): maxSize( size )
void History::addItem( Item const & item )
{
+ if( !enabled() )
+ return;
+
if ( item.word.size() > 60 )
{
// The search looks bogus. Don't save it.
View
11 history.hh
@@ -53,6 +53,10 @@ public:
/// item gets removed from the end of the list.
void addItem( Item const & );
+ /// Remove item with given index from list
+ void removeItem( int index )
+ { items.removeAt( index ); }
+
/// Attempts saving history. Returns true if succeeded - false otherwise.
/// Since history isn't really that valuable, failures can be ignored.
bool save() const;
@@ -64,6 +68,12 @@ public:
QList< Item > const & getItems() const
{ return items; }
+ /// Enable/disable add words to hystory
+ void enableAdd( bool enable )
+ { addingEnabled = enable; }
+ bool enabled()
+ { return addingEnabled; }
+
signals:
/// Signals the changes in items in response to addItem() or clear().
@@ -73,6 +83,7 @@ private:
QList< Item > items;
unsigned maxSize;
+ bool addingEnabled;
};
#endif
View
6 maintabwidget.cc
@@ -17,11 +17,17 @@ void MainTabWidget::setHideSingleTab(bool hide)
void MainTabWidget::tabInserted(int index)
{
updateTabBarVisibility();
+
+ // Avoid bug in Qt 4.8.0
+ setUsesScrollButtons( count() > 10 );
}
void MainTabWidget::tabRemoved(int index)
{
updateTabBarVisibility();
+
+ // Avoid bug in Qt 4.8.0
+ setUsesScrollButtons( count() > 10 );
}
void MainTabWidget::updateTabBarVisibility()
View
135 mainwindow.cc
@@ -25,6 +25,7 @@ using std::pair;
MainWindow::MainWindow( Config::Class & cfg_ ):
commitDataCompleted( false ),
+ showHistory( false ),
trayIcon( 0 ),
groupLabel( &searchPaneTitleBar ),
groupList( &searchPaneTitleBar ),
@@ -45,7 +46,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
trayIconMenu( this ),
addTab( this ),
cfg( cfg_ ),
- history( History::Load() ),
+ history( History::Load(), cfg_.preferences.maxStringsInHistory ),
dictionaryBar( this, cfg.mutedDictionaries, configEvents ),
articleMaker( dictionaries, groupInstances, cfg.preferences.displayStyle ),
articleNetMgr( this, dictionaries, articleMaker,
@@ -315,12 +316,13 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
this, SLOT(editCurrentGroup()) );
// History
-
+/*
connect( &history, SIGNAL( itemsChanged() ),
this, SLOT( historyChanged() ) );
connect( ui.menuHistory, SIGNAL(triggered(QAction*)),
this, SLOT(menuHistoryTriggered(QAction*)), Qt::QueuedConnection );
+*/
// Show tray icon early so the user would be happy. It won't be functional
// though until the program inits fully.
@@ -436,7 +438,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
makeDictionaries();
// After we have dictionaries and groups, we can populate history
- historyChanged();
+// historyChanged();
addNewTab();
@@ -536,6 +538,8 @@ MainWindow::~MainWindow()
delete w;
}
+
+ history.save();
}
void MainWindow::commitData( QSessionManager & )
@@ -1273,7 +1277,8 @@ void MainWindow::currentGroupChanged( QString const & )
// Update word search results
- translateInputChanged( ui.translateLine->text() );
+ if( !showHistory )
+ translateInputChanged( ui.translateLine->text() );
updateCurrentGroupProperty();
}
@@ -1489,7 +1494,8 @@ void MainWindow::updateMatchResults( bool finished )
void MainWindow::applyMutedDictionariesState()
{
// Redo the current search request
- translateInputChanged( ui.translateLine->text() );
+ if( !showHistory )
+ translateInputChanged( ui.translateLine->text() );
ArticleView *view = getCurrentArticleView();
@@ -1571,6 +1577,24 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
return true;
}
+ if( showHistory && keyEvent->matches( QKeySequence::Delete ) && ui.wordList->count() )
+ {
+ // Delete word from history
+
+ QList<QListWidgetItem *> selectedItems = ui.wordList->selectedItems();
+
+ if( selectedItems.size() )
+ {
+ int index = ui.wordList->row( selectedItems.at( 0 ) );
+ history.removeItem( index );
+ QListWidgetItem *item = ui.wordList->takeItem( index );
+ if( item )
+ delete item;
+ }
+
+ return true;
+ }
+
// Handle typing events used to initiate new lookups
// TODO: refactor to eliminate duplication (see below)
@@ -1696,15 +1720,21 @@ void MainWindow::activeArticleChanged( QString const & id )
void MainWindow::typingEvent( QString const & t )
{
if ( t == "\n" || t == "\r" )
- focusTranslateLine();
+ {
+ if( ui.translateLine->isEnabled() )
+ focusTranslateLine();
+ }
else
{
if ( ui.searchPane->isFloating() || ui.dictsPane->isFloating() )
ui.searchPane->activateWindow();
- ui.translateLine->setText( t );
- ui.translateLine->setFocus();
- ui.translateLine->setCursorPosition( t.size() );
+ if( ui.translateLine->isEnabled() )
+ {
+ ui.translateLine->setText( t );
+ ui.translateLine->setFocus();
+ ui.translateLine->setCursorPosition( t.size() );
+ }
}
}
@@ -1732,8 +1762,11 @@ void MainWindow::showTranslationFor( QString const & inWord,
// Add to history
- history.addItem( History::Item( group, inWord.trimmed() ) );
- history.save();
+ if( !showHistory )
+ {
+ history.addItem( History::Item( group, inWord.trimmed() ) );
+// history.save();
+ }
updateBackForwardButtons();
@@ -2177,6 +2210,7 @@ void MainWindow::toggleMenuBarTriggered(bool announce)
menuBar()->setVisible( !cfg.preferences.hideMenubar );
}
+/*
void MainWindow::historyChanged()
{
// Rebuild history menu
@@ -2205,7 +2239,9 @@ void MainWindow::historyChanged()
ui.clearHistory->setEnabled( items.size() );
}
+*/
+/*
void MainWindow::menuHistoryTriggered( QAction * action )
{
if ( action->data().type() != QVariant::Int )
@@ -2222,11 +2258,15 @@ void MainWindow::menuHistoryTriggered( QAction * action )
showTranslationFor( item.word, item.groupId );
}
+*/
void MainWindow::on_clearHistory_activated()
{
history.clear();
history.save();
+
+ if( showHistory )
+ ui.wordList->clear();
}
void MainWindow::on_newTab_activated()
@@ -2480,7 +2520,80 @@ ArticleView * MainWindow::getCurrentArticleView()
void MainWindow::wordReceived( const QString & word)
{
+ if( showHistory )
+ return;
+
toggleMainWindow( true );
ui.translateLine->setText( word );
translateInputFinished();
}
+
+void MainWindow::on_showHideHistory_activated()
+{
+static bool needHideSearchPane;
+ if( showHistory )
+ {
+ if( needHideSearchPane )
+ {
+ ui.searchPane->hide();
+ needHideSearchPane = false;
+ ui.searchPane->toggleViewAction()->setChecked( false );
+ }
+ ui.searchPane->toggleViewAction()->setEnabled( true );
+
+ ui.showHideHistory->setText( tr( "&Show" ) );
+ showHistory = false;
+
+ connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
+ this, SLOT( translateInputChanged( QString const & ) ) );
+
+ ui.translateLine->clear();
+ ui.translateLine->setEnabled( true );
+ ui.translateLine->setProperty( "noResults", false );
+ setStyleSheet( styleSheet() );
+
+ ui.wordList->clear();
+
+ history.enableAdd( true );
+ }
+ else
+ {
+ history.enableAdd( false );
+
+ disconnect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
+ this, SLOT( translateInputChanged( QString const & ) ) );
+
+ if( !ui.searchPane->isVisible() )
+ {
+ ui.searchPane->show();
+ ui.searchPane->toggleViewAction()->setChecked( true );
+ needHideSearchPane = true;
+ }
+ ui.searchPane->toggleViewAction()->setEnabled( false );
+
+ ui.showHideHistory->setText( tr( "&Hide" ) );
+ showHistory = true;
+
+ ui.translateLine->setEnabled( false );
+ ui.translateLine->setText( tr( "History view mode" ) );
+ ui.translateLine->setProperty( "noResults", true );
+ setStyleSheet( styleSheet() );
+
+ ui.wordList->setUpdatesEnabled( false );
+ ui.wordList->clear();
+
+ QList< History::Item > const & items = history.getItems();
+ for( int x = 0; x < items.size(); ++x )
+ {
+ History::Item const * i = &items[ x ];
+ QListWidgetItem * s = new QListWidgetItem( i->word, ui.wordList );
+ if (s->text().at(0).direction() == QChar::DirR)
+ s->setTextAlignment(Qt::AlignRight);
+ if (s->text().at(0).direction() == QChar::DirL)
+ s->setTextAlignment(Qt::AlignLeft);
+ ui.wordList->addItem( s );
+ }
+
+ ui.wordList->setUpdatesEnabled( true );
+ }
+}
View
8 mainwindow.hh
@@ -53,6 +53,8 @@ private:
void commitData();
bool commitDataCompleted;
+ bool showHistory;
+
QSystemTrayIcon * trayIcon;
Ui::MainWindow ui;
@@ -299,8 +301,8 @@ private slots:
void useSmallIconsInToolbarsTriggered();
void toggleMenuBarTriggered( bool announce = true );
- void historyChanged();
- void menuHistoryTriggered( QAction * );
+// void historyChanged();
+// void menuHistoryTriggered( QAction * );
void on_clearHistory_activated();
void on_newTab_activated();
@@ -315,6 +317,8 @@ private slots:
void on_saveArticle_activated();
void on_rescanFiles_activated();
+
+ void on_showHideHistory_activated();
};
#endif
View
9 mainwindow.ui
@@ -61,7 +61,7 @@
<x>0</x>
<y>0</y>
<width>653</width>
- <height>21</height>
+ <height>18</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -114,7 +114,7 @@
<property name="title">
<string>H&amp;istory</string>
</property>
- <addaction name="separator"/>
+ <addaction name="showHideHistory"/>
<addaction name="clearHistory"/>
</widget>
<addaction name="menuFile"/>
@@ -411,6 +411,11 @@
<string>&amp;Configuration Folder</string>
</property>
</action>
+ <action name="showHideHistory">
+ <property name="text">
+ <string>&amp;Show</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
View
18 mediawiki.cc
@@ -294,11 +294,17 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
// Update any special index.php pages to be absolute
articleString.replace( QRegExp( "<a\\shref=\"(/(\\w*/)*index.php\\?)" ),
QString( "<a href=\"%1\\1" ).arg( wikiUrl.toString() ) );
- // Replace the href="/foo/bar/Baz" to just href="Baz".
- articleString.replace( QRegExp( "<a\\shref=\"/([\\w\\.]*/)*" ), "<a href=\"" );
-
+
+ // audio url
+ articleString.replace( QRegExp( "<a\\s+href=\"(//upload\\.wikimedia\\.org/wikipedia/commons/[^\"'&]*\\.ogg)" ),
+ QString::fromStdString( addAudioLink( "\"http:\\1\"",this->dictID )+ "<a href=\"http:\\1" ) );
+
// Add "http:" to image source urls
articleString.replace( " src=\"//", " src=\"http://" );
+
+ // Replace the href="/foo/bar/Baz" to just href="Baz".
+ articleString.replace( QRegExp( "<a\\shref=\"/([\\w\\.]*/)*" ), "<a href=\"" );
+
//fix audio
articleString.replace( QRegExp("<button\\s+[^>]*(upload\\.wikimedia\\.org/wikipedia/commons/[^\"'&]*\\.ogg)[^>]*>\\s*<[^<]*</button>"),
QString::fromStdString(addAudioLink("\"http://\\1\"",this->dictID)+
@@ -312,7 +318,11 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
if ( articleString == before )
break;
}
-
+
+ //fix file: url
+ articleString.replace( QRegExp("<a\\s+href=\"([^:/\"]+:[^/\"]+\")" ),
+ QString( "<a href=\"%1/index.php?title=\\1" ).arg( url ));
+
QByteArray articleBody = articleString.toUtf8();
DPRINTF( "Article body after: %s\n", articleBody.data() );
View
2  scanpopup.cc
@@ -409,7 +409,7 @@ void ScanPopup::initiateTranslation()
history.addItem( History::Item( ui.groupList->getCurrentGroup(),
inputWord.trimmed() ) );
- history.save();
+// history.save();
}
vector< sptr< Dictionary::Class > > const & ScanPopup::getActiveDicts()

No commit comments for this range

Something went wrong with that request. Please try again.