merged with upstream/master

This commit is contained in:
csoler 2016-05-01 15:22:13 -04:00
commit 70648398e2
39 changed files with 1086 additions and 584 deletions

View file

@ -219,8 +219,8 @@ TransfersDialog::TransfersDialog(QWidget *parent)
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
QShortcut *Shortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.downloadList, 0, 0, Qt::WidgetShortcut);
connect(Shortcut, SIGNAL(activated()), this, SLOT( cancel ()));
mShortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.downloadList, 0, 0, Qt::WidgetShortcut);
connect(mShortcut, SIGNAL(activated()), this, SLOT( cancel ()));
//Selection Setup
selection = ui.downloadList->selectionModel();
@ -942,7 +942,8 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo)
qlonglong completed = fileInfo.transfered;
qlonglong remaining = fileInfo.size - fileInfo.transfered;
qlonglong downloadtime = (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0);
qlonglong downloadtime = (fileInfo.tfRate > 0)?( (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0) ) : 0 ;
qint64 qi64LastDL = fileInfo.lastTS ; //std::numeric_limits<qint64>::max();
if (qi64LastDL == 0) // file is complete, or any raison why the time has not been set properly
@ -1355,7 +1356,7 @@ void TransfersDialog::insertTransfers()
qlonglong fileSize = info.size;
qlonglong completed = pit->transfered;
// double progress = (info.size > 0)?(pit->transfered * 100.0 / info.size):0.0;
qlonglong remaining = (info.size - pit->transfered) / (pit->tfRate * 1024.0);
qlonglong remaining = (pit->tfRate>0)?((info.size - pit->transfered) / (pit->tfRate * 1024.0)):0;
// Estimate the completion. We need something more accurate, meaning that we need to
// transmit the completion info.

View file

@ -31,6 +31,7 @@
#define IMAGE_TRANSFERS ":/icons/ktorrent_128.png"
class QShortcut;
class DLListDelegate;
class ULListDelegate;
class QStandardItemModel;
@ -243,6 +244,8 @@ private:
QString downloads;
QString uploads;
QShortcut *mShortcut ;
/** Qt Designer generated object */
Ui::TransfersDialog ui;

View file

@ -1725,7 +1725,11 @@ void ChatWidget::quote()
void ChatWidget::dropPlacemark()
{
ui->textBrowser->append("----------");
ui->textBrowser->moveCursor(QTextCursor::End); // *append* inserts text at end but with formatting in effect at
ui->textBrowser->append("----------"); // current cursor position, such as in the middle of a hotlink,
// which would be strange. This OTOH inserts text with
// formatting in effect on the last line, which may be strange
// or not.
}
void ChatWidget::saveImage()

View file

@ -10,6 +10,7 @@ SubscribeToolButton::SubscribeToolButton(QWidget *parent) :
{
mSubscribed = false;
mMenu = NULL ;
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
#ifdef USE_MENUBUTTONPOPUP
@ -46,14 +47,18 @@ void SubscribeToolButton::updateUi()
setIcon(QIcon(":/images/accepted16.png"));
setText(tr("Subscribed"));
QMenu *menu = new QMenu;
menu->addAction(QIcon(":/images/cancel.png"), tr("Unsubscribe"), this, SLOT(unsubscribePrivate()));
if(mMenu != NULL) // that's because setMenu does not give away memory ownership
delete mMenu ;
mMenu = new QMenu;
mMenu->addAction(QIcon(":/images/cancel.png"), tr("Unsubscribe"), this, SLOT(unsubscribePrivate()));
if (!mSubscribedActions.empty()) {
menu->addSeparator();
menu->addActions(mSubscribedActions);
mMenu->addSeparator();
mMenu->addActions(mSubscribedActions);
}
setMenu(menu);
setMenu(mMenu);
#ifndef USE_MENUBUTTONPOPUP
disconnect(this, SIGNAL(clicked()), this, SLOT(subscribePrivate()));

View file

@ -26,6 +26,7 @@ private:
private:
bool mSubscribed;
QList<QAction*> mSubscribedActions;
QMenu *mMenu ;
};
#endif // SUBSCRIBETOOLBUTTON_H

View file

@ -259,7 +259,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
}
}
static void convolveWithGaussian(double *forceMap,int S,int /*s*/)
static void convolveWithGaussian(double *forceMap,unsigned int S,int /*s*/)
{
static double *bf = NULL ;
@ -267,8 +267,8 @@ static void convolveWithGaussian(double *forceMap,int S,int /*s*/)
{
bf = new double[S*S*2] ;
for(int i=0;i<S;++i)
for(int j=0;j<S;++j)
for(unsigned int i=0;i<S;++i)
for(unsigned int j=0;j<S;++j)
{
int x = (i<S/2)?i:(S-i) ;
int y = (j<S/2)?j:(S-j) ;
@ -284,8 +284,8 @@ static void convolveWithGaussian(double *forceMap,int S,int /*s*/)
unsigned long nn[2] = {S,S};
fourn(&forceMap[-1],&nn[-1],2,1) ;
for(int i=0;i<S;++i)
for(int j=0;j<S;++j)
for(unsigned int i=0;i<S;++i)
for(unsigned int j=0;j<S;++j)
{
float a = forceMap[2*(i+S*j)]*bf[2*(i+S*j)] - forceMap[2*(i+S*j)+1]*bf[2*(i+S*j)+1] ;
float b = forceMap[2*(i+S*j)]*bf[2*(i+S*j)+1] + forceMap[2*(i+S*j)+1]*bf[2*(i+S*j)] ;
@ -296,7 +296,7 @@ static void convolveWithGaussian(double *forceMap,int S,int /*s*/)
fourn(&forceMap[-1],&nn[-1],2,-1) ;
for(int i=0;i<S*S*2;++i)
for(unsigned int i=0;i<S*S*2;++i)
forceMap[i] /= S*S;
}

View file

@ -362,21 +362,21 @@ Rshare::showUsageMessageBox()
out << "<table>";
//out << trow(tcol("-"ARG_HELP) +
// tcol(tr("Displays this usage message and exits.")));
out << trow(tcol("-"ARG_RESET) +
out << trow(tcol("-" ARG_RESET) +
tcol(tr("Resets ALL stored RetroShare settings.")));
out << trow(tcol("-"ARG_DATADIR" &lt;dir&gt;") +
out << trow(tcol("-" ARG_DATADIR" &lt;dir&gt;") +
tcol(tr("Sets the directory RetroShare uses for data files.")));
out << trow(tcol("-"ARG_LOGFILE" &lt;file&gt;") +
out << trow(tcol("-" ARG_LOGFILE" &lt;file&gt;") +
tcol(tr("Sets the name and location of RetroShare's logfile.")));
out << trow(tcol("-"ARG_LOGLEVEL" &lt;level&gt;") +
out << trow(tcol("-" ARG_LOGLEVEL" &lt;level&gt;") +
tcol(tr("Sets the verbosity of RetroShare's logging.") +
"<br>[" + Log::logLevels().join("|") +"]"));
out << trow(tcol("-"ARG_GUISTYLE" &lt;style&gt;") +
out << trow(tcol("-" ARG_GUISTYLE" &lt;style&gt;") +
tcol(tr("Sets RetroShare's interface style.") +
"<br>[" + QStyleFactory::keys().join("|") + "]"));
out << trow(tcol("-"ARG_GUISTYLESHEET" &lt;stylesheet&gt;") +
out << trow(tcol("-" ARG_GUISTYLESHEET" &lt;stylesheet&gt;") +
tcol(tr("Sets RetroShare's interface stylesheets.")));
out << trow(tcol("-"ARG_LANGUAGE" &lt;language&gt;") +
out << trow(tcol("-" ARG_LANGUAGE" &lt;language&gt;") +
tcol(tr("Sets RetroShare's language.") +
"<br>[" + LanguageSupport::languageCodes().join("|") + "]"));
out << "</table>";

View file

@ -17,6 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* ccr . 2016 Jan 30 . Change regular expression(s) for identifying
* . . hotlinks in feral text.
*
****************************************************************/
#include <QApplication>
@ -56,7 +60,7 @@ protected:
public:
const EmbeddedType myType;
QRegExp myRE;
QList<QRegExp> myREs;
};
/**
@ -67,10 +71,42 @@ class EmbedInHtmlAhref : public EmbedInHtml
public:
EmbedInHtmlAhref() : EmbedInHtml(Ahref)
{
myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)");
}
};
// myRE.setPattern("(\\bretroshare://[^\\s]*)|(\\bhttps?://[^\\s]*)|(\\bfile://[^\\s]*)|(\\bwww\\.[^\\s]*)");
// The following regular expressions for finding URLs in
// plain text are borrowed from *gnome-terminal*:
QString regPassCharset = "[-\\w,?;\\.:/!%$^*&~\\\"#']";
QString regHost = "[-\\w]+(\\.[-\\w]+)*";
QString regPort = "(?:\\:\\d{1,5})?";
QString regPathCharset = "[-\\w_$\\.+!*,;@&=?/~#%]";
QString regPathTermSet = "[^\\]'.}<>) \\t\\r\\n,\\\"]";
QStringList regSchemes;
// regSchemes.append("news:");
// regSchemes.append("telnet:");
// regSchemes.append("nntp:");
// regSchemes.append("file:/");
regSchemes.append("https?:");
// regSchemes.append("ftps?:");
// regSchemes.append("sftp:");
// regSchemes.append("webcal:");
regSchemes.append("retroshare:");
QString regScheme = "((?:" + regSchemes.join(")|(?:") + "))";
QString regUserPass = "[-\\w]+(?:%s+)?" % regPassCharset;
QString regUrlPath = "(?:(/" + regPathCharset + "+(?:[(]" + regPathCharset +"*[)])*" + regPathCharset + "*)*" + regPathTermSet + ")?";
QStringList regHotLinkFinders;
regHotLinkFinders.append(regScheme + "//(?:" + regUserPass + "@)?"+ regHost + regPort + regUrlPath);
// regHotLinkFinders.append("(?:(?:www)|(?:ftp))[-\\w]*\\." + regHost + regPort + regUrlPath);
// regHotLinkFinders.append("(?:(?:callto:)|(?:h323:)|(?:sip:))[-\\w][-\\w\\.]*(?:" + regPort + "/[a-z0-9]+)?@" + regHost);
// regHotLinkFinders.append("(?:mailto:)?[-\\w][-\\w\\.]*@[-\\w]+\\." + regHost);
// regHotLinkFinders.append("news:[\\w^_{|}~!\\\"#$%&'()*+,\\./;:=?`]+");
while (!regHotLinkFinders.isEmpty()) {
myREs.append(QRegExp(regHotLinkFinders.takeFirst(), Qt::CaseInsensitive));
};
}
};
/**
* This class is used to store information for embedding smileys into <img/> tags.
*
@ -134,7 +170,7 @@ void RsHtml::initEmoticons(const QHash< QString, QString >& hash)
*/
}
newRE.chop(1); // remove last |
defEmbedImg.myRE.setPattern(newRE);
defEmbedImg.myREs.append(QRegExp(newRE));
}
bool RsHtml::canReplaceAnchor(QDomDocument &/*doc*/, QDomElement &/*element*/, const RetroShareLink &link)
@ -243,7 +279,7 @@ void RsHtml::replaceAnchorWithImg(QDomDocument &doc, QDomElement &element, QText
* nodes. Any other kind of node is terminal.
*
* If the node is of type Text, its data is checked against the user-provided
* regular expression. If there is a match, the text is cut in three parts: the
* regular expression(s). If there is a match, the text is cut in three parts: the
* preceding part that will be inserted before, the part to be replaced, and the
* following part which will be itself checked against the regular expression.
*
@ -252,13 +288,10 @@ void RsHtml::replaceAnchorWithImg(QDomDocument &doc, QDomElement &element, QText
*
* @param[in] doc The whole DOM tree, necessary to create new nodes
* @param[in,out] currentElement The current node (which is of type Element)
* @param[in] embedInfos The regular expression and the type of embedding to use
* @param[in] embedInfos The regular expression(s) and the type of embedding to use
*/
void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomElement& currentElement, EmbedInHtml& embedInfos, ulong flag)
{
if(embedInfos.myRE.pattern().length() == 0) // we'll get stuck with an empty regexp
return;
QDomNodeList children = currentElement.childNodes();
for(uint index = 0; index < (uint)children.length(); index++) {
QDomNode node = children.item(index);
@ -298,15 +331,20 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
}
}
else if(node.isText()) {
// child is a text, we parse it
QString tempText = node.toText().data();
if(embedInfos.myRE.indexIn(tempText) == -1)
// child is a text, we parse it
QString tempText = node.toText().data();
for (int patNdx = 0; patNdx < embedInfos.myREs.size(); ++patNdx) {
QRegExp myRE = embedInfos.myREs.at(patNdx);
if(myRE.pattern().length() == 0) // we'll get stuck with an empty regexp
return;
if(myRE.indexIn(tempText) == -1)
continue;
// there is at least one link inside, we start replacing
int currentPos = 0;
int nextPos = 0;
while((nextPos = embedInfos.myRE.indexIn(tempText, currentPos)) != -1) {
while((nextPos = myRE.indexIn(tempText, currentPos)) != -1) {
// if nextPos == 0 it means the text begins by a link
if(nextPos > 0) {
QDomText textPart = doc.createTextNode(tempText.mid(currentPos, nextPos - currentPos));
@ -320,10 +358,10 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
case Ahref:
{
insertedTag = doc.createElement("a");
insertedTag.setAttribute("href", embedInfos.myRE.cap(0));
insertedTag.appendChild(doc.createTextNode(embedInfos.myRE.cap(0)));
insertedTag.setAttribute("href", myRE.cap(0));
insertedTag.appendChild(doc.createTextNode(myRE.cap(0)));
RetroShareLink link(embedInfos.myRE.cap(0));
RetroShareLink link(myRE.cap(0));
if (link.valid()) {
QString title = link.title();
if (!title.isEmpty()) {
@ -340,11 +378,11 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
{
insertedTag = doc.createElement("img");
const EmbedInHtmlImg& embedImg = static_cast<const EmbedInHtmlImg&>(embedInfos);
// embedInfos.myRE.cap(0) may include spaces at the end/beginning -> trim!
insertedTag.setAttribute("src", embedImg.smileys[embedInfos.myRE.cap(0).trimmed()]);
// myRE.cap(0) may include spaces at the end/beginning -> trim!
insertedTag.setAttribute("src", embedImg.smileys[myRE.cap(0).trimmed()]);
/*
* NOTE
* Trailing spaces are matched, too. This leads to embedInfos.myRE.matchedLength() being incorrect.
* Trailing spaces are matched, too. This leads to myRE.matchedLength() being incorrect.
* This hack reduces nextPos by one so that the new value of currentPos is calculated corretly.
* This is needed to match multiple smileys since the leading whitespace in front of a smiley is required!
*
@ -353,7 +391,7 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
* NOTE
* Preceding spaces are also matched and removed.
*/
if(embedInfos.myRE.cap(0).endsWith(' '))
if(myRE.cap(0).endsWith(' '))
nextPos--;
}
break;
@ -362,7 +400,7 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
currentElement.insertBefore(insertedTag, node);
index++;
currentPos = nextPos + embedInfos.myRE.matchedLength();
currentPos = nextPos + myRE.matchedLength();
}
// text after the last link, only if there's one, don't touch the index
@ -375,10 +413,18 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme
index--;
currentElement.removeChild(node);
break;
// We'd better not expect that
// subsequent hotlink patterns
// wouldn't also match replacements
// we've already made. They might, so
// skip 'em to be safe.
};
}
}
}
/**
* Save space and tab out of bracket that XML loose.
*
@ -612,7 +658,7 @@ static void findBestColor(QString &val, qreal bglum, qreal desiredContrast)
*/
static void optimizeHtml(QDomDocument& doc
, QDomElement& currentElement
, QHash<QString, QStringList*> &stylesList
, QHash<QString, QStringList> &stylesList
, QHash<QString, QString> &knownStyle)
{
if (doc.documentElement().namedItem("style").toElement().attributeNode("RSOptimized").isAttr()) {
@ -631,10 +677,10 @@ static void optimizeHtml(QDomDocument& doc
QString keyvalue = pair.at(1);
keyvalue.replace(";","");
QStringList classUsingIt(pair.at(0).split(','));
QStringList* exported = new QStringList();
QStringList exported ;
foreach (QString keyVal, classUsingIt) {
if(!keyVal.trimmed().isEmpty()) {
exported->append(keyVal.trimmed().replace(".",""));
exported.append(keyVal.trimmed().replace(".",""));
}
}
@ -759,14 +805,10 @@ static void optimizeHtml(QDomDocument& doc
foreach (QString pair, styles) {
pair.replace(" ","");
if (!pair.isEmpty()) {
QStringList* stylesListItem = stylesList.value(pair);
if(!stylesListItem){
// If value doesn't exist create it
stylesListItem = new QStringList();
stylesList.insert(pair, stylesListItem);
}
QStringList& stylesListItem = stylesList[pair];
//Add the new class to this value
stylesListItem->push_back(className);
stylesListItem.push_back(className);
}
}
}
@ -800,7 +842,7 @@ static void optimizeHtml(QDomDocument& doc
* @param desiredMinimumFontSize: Minimum font size.
*/
static void styleCreate(QDomDocument& doc
, QHash<QString, QStringList*> stylesList
, QHash<QString, QStringList>& stylesList
, unsigned int flag
, qreal bglum
, qreal desiredContrast
@ -840,12 +882,12 @@ static void styleCreate(QDomDocument& doc
QString style = "";
QHashIterator<QString, QStringList*> it(stylesList);
QHashIterator<QString, QStringList> it(stylesList);
while(it.hasNext()) {
it.next();
QStringList* classUsingIt = it.value();
const QStringList& classUsingIt ( it.value()) ;
bool first = true;
foreach(QString className, *classUsingIt) {
foreach(QString className, classUsingIt) {
if (!className.trimmed().isEmpty()) {
style += QString(first?".":",.") + className;// + " ";
first = false;
@ -961,7 +1003,8 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/
}
QDomElement body = doc.documentElement();
QHash<QString, QStringList*> stylesList;
QHash<QString, QStringList> stylesList;
QHash<QString, QString> knownStyle;
::optimizeHtml(doc, body, stylesList, knownStyle);