+ // Get the new domain string.
+ QString newDomain = cookie.domain();
+
+ // Check to see if the domain already exists in the model.
+ QList<QStandardItem*> currentDomainStandardItemList = standardItemModelPointer->findItems(newDomain);
+
+ // Create a domain standard item pointer.
+ QStandardItem *domainStandardItemPointer;
+
+ // Prepare the domain standard item pointer.
+ if (currentDomainStandardItemList.isEmpty()) // The domain doesn't currently exist in the tree.
+ {
+ // Create a list for the domain standard items.
+ QList<QStandardItem*> domainStandardItemList;
+
+ // Create the new domain standard items.
+ domainStandardItemPointer = new QStandardItem(newDomain);
+ QStandardItem *pathStandardItemPointer = new QStandardItem(QStringLiteral(""));
+ QStandardItem *expirationDateStandardItemPointer = new QStandardItem(QStringLiteral(""));
+ QStandardItem *isHttpOnlyStandardItemPointer = new QStandardItem(QStringLiteral(""));
+ QStandardItem *isSecureStandardItemPointer = new QStandardItem(QStringLiteral(""));
+ QStandardItem *valueStandardItemPointer = new QStandardItem(QStringLiteral(""));
+
+ // Disable editing of the domain.
+ domainStandardItemPointer->setEditable(false);
+ pathStandardItemPointer->setEditable(false);
+ expirationDateStandardItemPointer->setEditable(false);
+ isHttpOnlyStandardItemPointer->setEditable(false);
+ isSecureStandardItemPointer->setEditable(false);
+ valueStandardItemPointer->setEditable(false);
+
+ // Populate the domain standard item list.
+ domainStandardItemList.append(domainStandardItemPointer);
+ domainStandardItemList.append(pathStandardItemPointer);
+ domainStandardItemList.append(expirationDateStandardItemPointer);
+ domainStandardItemList.append(isHttpOnlyStandardItemPointer);
+ domainStandardItemList.append(isSecureStandardItemPointer);
+ domainStandardItemList.append(valueStandardItemPointer);
+
+ // Create the insert domain row number.
+ int insertDomainRowNumber = 0;
+
+ // Get the number of domains in the tree.
+ int numberOfDomains = standardItemModelPointer->invisibleRootItem()->rowCount();
+
+ // Get the new domain strings.
+ QString newDomainTopLevelDomain = newDomain.section('.', -1);
+ QString newDomainSecondLevelDomain = newDomain.section('.', -2);
+ QString newDomainThirdLevelDomain = newDomain.section('.', -3);
+
+ // Iterate through all the domains.
+ for (int i = 0; i < numberOfDomains; ++i)
+ {
+ // Get the current domain strings.
+ QString currentDomain = standardItemModelPointer->invisibleRootItem()->child(i, 0)->index().data().toString();
+ QString currentDomainTopLevelDomain = currentDomain.section('.', -1);
+ QString currentDomainSecondLevelDomain = currentDomain.section('.', -2);
+ QString currentDomainThirdLevelDomain = currentDomain.section('.', -3);
+
+ // Check to see if the new domain should be inserted after the current domain.
+ if (newDomainTopLevelDomain > currentDomainTopLevelDomain)
+ {
+ // Insert the new domain after the current domain.
+ insertDomainRowNumber = i + 1;
+ }
+ else if ((newDomainTopLevelDomain == currentDomainTopLevelDomain) && (newDomainSecondLevelDomain > currentDomainSecondLevelDomain))
+ {
+ // Insert the new domain after the current domain.
+ insertDomainRowNumber = i + 1;
+ }
+ else if ((newDomainSecondLevelDomain == currentDomainSecondLevelDomain) && (newDomainThirdLevelDomain > currentDomainThirdLevelDomain))
+ {
+ // Insert the new domain after the current domain.
+ insertDomainRowNumber = i + 1;
+ }
+ else if ((newDomainThirdLevelDomain == currentDomainThirdLevelDomain) && (newDomain > currentDomain))
+ {
+ // Insert the new domain after the current domain.
+ insertDomainRowNumber = i + 1;
+ }
+ }
+
+ // Add the domain to the tree.
+ standardItemModelPointer->invisibleRootItem()->insertRow(insertDomainRowNumber, domainStandardItemList);
+ }
+ else // The domain already exists in the tree.
+ {
+ // Use the current domain standard item.
+ domainStandardItemPointer = currentDomainStandardItemList[0];
+ }
+
+ // Get strings for the new cookie name and path (used later in the placement of the row).
+ QString newCookieName = QString(cookie.name());
+ QString newCookiePath = QString(cookie.path());
+
+ // Create a list for the cookie standard items.
+ QList<QStandardItem*> cookieStandardItemList;
+
+ // Create the cookie standard items.
+ QStandardItem *nameStandardItemPointer = new QStandardItem(newCookieName);
+ QStandardItem *pathStandardItemPointer = new QStandardItem(newCookiePath);
+ QStandardItem *expirationDateStandardItemPointer = new QStandardItem(QString(cookie.expirationDate().toString()));
+ QStandardItem *isHttpOnlyStandardItemPointer = new QStandardItem(QString(cookie.isHttpOnly() ? i18n("yes") : i18n("no")));
+ QStandardItem *isSecureStandardItemPointer = new QStandardItem(QString(cookie.isSecure() ? i18n("yes") : i18n("no")));
+ QStandardItem *valueStandardItemPointer = new QStandardItem(QString(cookie.value()));
+
+ // Disable editing of the cookie standard items.
+ nameStandardItemPointer->setEditable(false);
+ pathStandardItemPointer->setEditable(false);
+ expirationDateStandardItemPointer->setEditable(false);
+ isHttpOnlyStandardItemPointer->setEditable(false);
+ isSecureStandardItemPointer->setEditable(false);
+ valueStandardItemPointer->setEditable(false);
+
+ // Populate the cookie standard item list.
+ cookieStandardItemList.append(nameStandardItemPointer);
+ cookieStandardItemList.append(pathStandardItemPointer);
+ cookieStandardItemList.append(expirationDateStandardItemPointer);
+ cookieStandardItemList.append(isHttpOnlyStandardItemPointer);
+ cookieStandardItemList.append(isSecureStandardItemPointer);
+ cookieStandardItemList.append(valueStandardItemPointer);
+
+ // Create the insert cookie row number.
+ int insertCookieRowNumber = 0;
+
+ // Get the number of cookies in the domain.
+ int numberOfCookies = domainStandardItemPointer->rowCount();
+
+ // Iterate through the cookies for this domain.
+ for (int i = 0; i < numberOfCookies; ++i)
+ {
+ // Get the current cookie name and path at the indicated row.
+ QString currentCookieName = domainStandardItemPointer->child(i, 0)->index().data().toString();
+ QString currentCookiePath = domainStandardItemPointer->child(i, 1)->index().data().toString();
+
+ // Check to see if the new cookie should be inserted after the current cookie.
+ if (newCookieName > currentCookieName)
+ {
+ // Insert the new cookie after the current cookie.
+ insertCookieRowNumber = i + 1;
+ }
+ else if ((newCookieName == currentCookieName) && (newCookiePath > currentCookiePath))
+ {
+ // Insert the new cookie after the current cookie.
+ insertCookieRowNumber = i + 1;
+ }
+ }
+
+ // Add the cookie to the tree.
+ domainStandardItemPointer->insertRow(insertCookieRowNumber, cookieStandardItemList);
+
+ // Get the new cookie model index.
+ QModelIndex newCookieIndex = nameStandardItemPointer->index();
+
+ // Set the new cookie to be the current index.
+ treeViewPointer->setCurrentIndex(newCookieIndex);
+
+ // Expand the parent of the new cookie.
+ treeViewPointer->expand(newCookieIndex.parent());