Logo Search packages:      
Sourcecode: basket version File versions  Download package

QStringList ItemFactory::textToURLList ( const QString &  text  ) 

Return a string list containing {url1, title1, url2, title2, url3, title3...}

Definition at line 129 of file itemfactory.cpp.

{
      // List to return:
      QStringList list;

      // Split lines:
      QStringList texts = QStringList::split('\n', text);

      // For each lines:
      QStringList::iterator it;
      for (it = texts.begin(); it != texts.end(); ++it) {
            // Strip white spaces:
            (*it) = (*it).stripWhiteSpace();

            // Don't care of empty entries:
            if ((*it).isEmpty())
                  continue;

            // Compute lower case equivalent:
            QString ltext = (*it).lower();

            /* Search for mail address ("*@*.*" ; "*" can contain '_', '-', or '.') and add protocol to it */
            QString mailExpString = "[\\w-\\.]+@[\\w-\\.]+\\.[\\w]+";
            QRegExp mailExp("^"+mailExpString+"$");
            if (mailExp.search(ltext) != -1) {
                  ltext.insert(0, "mailto:");
                  (*it).insert(0, "mailto:");
            }

            // TODO: Recognize "<link>" (link between '<' and '>')
            // TODO: Replace " at " by "@" and " dot " by "." to look for e-mail addresses

            /* Search for mail address like "Name <address@provider.net>" */
            QRegExp namedMailExp("^([\\w\\s]+)\\s<("+mailExpString+")>$");
            //namedMailExp.setCaseSensitive(true); // For the name to be keeped with uppercases // DOESN'T WORK !
            if (namedMailExp.search(ltext) != -1) {
                  QString name    = namedMailExp.cap(1);
                  QString address = "mailto:" + namedMailExp.cap(2);
                  // Threat it NOW, as it's an exception (it have a title):
                  list.append(address);
                  list.append(name);
                  continue;
            }

            /* Search for an url and create an URL item */
            if ( ltext.startsWith("/") && ltext[1] != '/' && ltext[1] != '*' || // Take files but not C/C++/... comments !
                   ltext.startsWith("file:")   ||
                   ltext.startsWith("http://") ||
                   ltext.startsWith("www.")    ||
                   ltext.startsWith("ftp")     ||
                   ltext.startsWith("mailto:")    ) {

                  // First, correct the text to use the good format for the url
                  if (ltext.startsWith( "/"))
                        (*it).insert(0, "file:");
                  if (ltext.startsWith("www."))
                        (*it).insert(0, "http://");
                  if (ltext.startsWith("ftp."))
                        (*it).insert(0, "ftp://");

                  // And create the Url item (or launcher if URL point a .desktop file)
                  list.append(*it);
                  list.append(""); // We don't have any title
            } else
                  return QStringList(); // FAILED: treat the text as a text, and not as a URL list!
      }
      return list;
}


Generated by  Doxygen 1.6.0   Back to index