author | zautrix <zautrix> | 2004-10-29 23:13:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-29 23:13:22 (UTC) |
commit | da80b510e4643fa3f78cf3f97af108e87097583d (patch) (unidiff) | |
tree | 01c328362a6bf1898853ba26fd5d48eb5cff1e27 /kabc/addressee.cpp | |
parent | aafa695508796e86e9f267633ea5e6965d876031 (diff) | |
download | kdepimpi-da80b510e4643fa3f78cf3f97af108e87097583d.zip kdepimpi-da80b510e4643fa3f78cf3f97af108e87097583d.tar.gz kdepimpi-da80b510e4643fa3f78cf3f97af108e87097583d.tar.bz2 |
added better category handling to kapi
-rw-r--r-- | kabc/addressee.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index eec0f1f..3ce733d 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1807,327 +1807,331 @@ Address::List Addressee::addresses( int type ) const | |||
1807 | if ( matchBinaryPattern( (*it).type(), type ) ) { | 1807 | if ( matchBinaryPattern( (*it).type(), type ) ) { |
1808 | list.append( *it ); | 1808 | list.append( *it ); |
1809 | } | 1809 | } |
1810 | } | 1810 | } |
1811 | 1811 | ||
1812 | return list; | 1812 | return list; |
1813 | } | 1813 | } |
1814 | 1814 | ||
1815 | Address Addressee::findAddress( const QString &id ) const | 1815 | Address Addressee::findAddress( const QString &id ) const |
1816 | { | 1816 | { |
1817 | Address::List::ConstIterator it; | 1817 | Address::List::ConstIterator it; |
1818 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 1818 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
1819 | if ( (*it).id() == id ) { | 1819 | if ( (*it).id() == id ) { |
1820 | return *it; | 1820 | return *it; |
1821 | } | 1821 | } |
1822 | } | 1822 | } |
1823 | return Address(); | 1823 | return Address(); |
1824 | } | 1824 | } |
1825 | 1825 | ||
1826 | void Addressee::insertCategory( const QString &c ) | 1826 | void Addressee::insertCategory( const QString &c ) |
1827 | { | 1827 | { |
1828 | detach(); | 1828 | detach(); |
1829 | mData->empty = false; | 1829 | mData->empty = false; |
1830 | 1830 | ||
1831 | if ( mData->categories.contains( c ) ) return; | 1831 | if ( mData->categories.contains( c ) ) return; |
1832 | 1832 | ||
1833 | mData->categories.append( c ); | 1833 | mData->categories.append( c ); |
1834 | } | 1834 | } |
1835 | 1835 | ||
1836 | void Addressee::removeCategory( const QString &c ) | 1836 | void Addressee::removeCategory( const QString &c ) |
1837 | { | 1837 | { |
1838 | detach(); | 1838 | detach(); |
1839 | 1839 | ||
1840 | QStringList::Iterator it = mData->categories.find( c ); | 1840 | QStringList::Iterator it = mData->categories.find( c ); |
1841 | if ( it == mData->categories.end() ) return; | 1841 | if ( it == mData->categories.end() ) return; |
1842 | 1842 | ||
1843 | mData->categories.remove( it ); | 1843 | mData->categories.remove( it ); |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | bool Addressee::hasCategory( const QString &c ) const | 1846 | bool Addressee::hasCategory( const QString &c ) const |
1847 | { | 1847 | { |
1848 | return ( mData->categories.contains( c ) ); | 1848 | return ( mData->categories.contains( c ) ); |
1849 | } | 1849 | } |
1850 | 1850 | ||
1851 | void Addressee::setCategories( const QStringList &c ) | 1851 | void Addressee::setCategories( const QStringList &c ) |
1852 | { | 1852 | { |
1853 | detach(); | 1853 | detach(); |
1854 | mData->empty = false; | 1854 | mData->empty = false; |
1855 | 1855 | ||
1856 | mData->categories = c; | 1856 | mData->categories = c; |
1857 | } | 1857 | } |
1858 | 1858 | ||
1859 | QStringList Addressee::categories() const | 1859 | QStringList Addressee::categories() const |
1860 | { | 1860 | { |
1861 | return mData->categories; | 1861 | return mData->categories; |
1862 | } | 1862 | } |
1863 | 1863 | ||
1864 | void Addressee::insertCustom( const QString &app, const QString &name, | 1864 | void Addressee::insertCustom( const QString &app, const QString &name, |
1865 | const QString &value ) | 1865 | const QString &value ) |
1866 | { | 1866 | { |
1867 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; | 1867 | if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; |
1868 | 1868 | ||
1869 | detach(); | 1869 | detach(); |
1870 | mData->empty = false; | 1870 | mData->empty = false; |
1871 | 1871 | ||
1872 | QString qualifiedName = app + "-" + name + ":"; | 1872 | QString qualifiedName = app + "-" + name + ":"; |
1873 | 1873 | ||
1874 | QStringList::Iterator it; | 1874 | QStringList::Iterator it; |
1875 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1875 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1876 | if ( (*it).startsWith( qualifiedName ) ) { | 1876 | if ( (*it).startsWith( qualifiedName ) ) { |
1877 | (*it) = qualifiedName + value; | 1877 | (*it) = qualifiedName + value; |
1878 | return; | 1878 | return; |
1879 | } | 1879 | } |
1880 | } | 1880 | } |
1881 | mData->custom.append( qualifiedName + value ); | 1881 | mData->custom.append( qualifiedName + value ); |
1882 | } | 1882 | } |
1883 | 1883 | ||
1884 | void Addressee::removeCustom( const QString &app, const QString &name) | 1884 | void Addressee::removeCustom( const QString &app, const QString &name) |
1885 | { | 1885 | { |
1886 | detach(); | 1886 | detach(); |
1887 | 1887 | ||
1888 | QString qualifiedName = app + "-" + name + ":"; | 1888 | QString qualifiedName = app + "-" + name + ":"; |
1889 | 1889 | ||
1890 | QStringList::Iterator it; | 1890 | QStringList::Iterator it; |
1891 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1891 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1892 | if ( (*it).startsWith( qualifiedName ) ) { | 1892 | if ( (*it).startsWith( qualifiedName ) ) { |
1893 | mData->custom.remove( it ); | 1893 | mData->custom.remove( it ); |
1894 | return; | 1894 | return; |
1895 | } | 1895 | } |
1896 | } | 1896 | } |
1897 | } | 1897 | } |
1898 | 1898 | ||
1899 | QString Addressee::custom( const QString &app, const QString &name ) const | 1899 | QString Addressee::custom( const QString &app, const QString &name ) const |
1900 | { | 1900 | { |
1901 | QString qualifiedName = app + "-" + name + ":"; | 1901 | QString qualifiedName = app + "-" + name + ":"; |
1902 | QString value; | 1902 | QString value; |
1903 | 1903 | ||
1904 | QStringList::ConstIterator it; | 1904 | QStringList::ConstIterator it; |
1905 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { | 1905 | for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { |
1906 | if ( (*it).startsWith( qualifiedName ) ) { | 1906 | if ( (*it).startsWith( qualifiedName ) ) { |
1907 | value = (*it).mid( (*it).find( ":" ) + 1 ); | 1907 | value = (*it).mid( (*it).find( ":" ) + 1 ); |
1908 | break; | 1908 | break; |
1909 | } | 1909 | } |
1910 | } | 1910 | } |
1911 | 1911 | ||
1912 | return value; | 1912 | return value; |
1913 | } | 1913 | } |
1914 | 1914 | ||
1915 | void Addressee::setCustoms( const QStringList &l ) | 1915 | void Addressee::setCustoms( const QStringList &l ) |
1916 | { | 1916 | { |
1917 | detach(); | 1917 | detach(); |
1918 | mData->empty = false; | 1918 | mData->empty = false; |
1919 | 1919 | ||
1920 | mData->custom = l; | 1920 | mData->custom = l; |
1921 | } | 1921 | } |
1922 | 1922 | ||
1923 | QStringList Addressee::customs() const | 1923 | QStringList Addressee::customs() const |
1924 | { | 1924 | { |
1925 | return mData->custom; | 1925 | return mData->custom; |
1926 | } | 1926 | } |
1927 | 1927 | ||
1928 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, | 1928 | void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, |
1929 | QString &email) | 1929 | QString &email) |
1930 | { | 1930 | { |
1931 | int startPos, endPos, len; | 1931 | int startPos, endPos, len; |
1932 | QString partA, partB, result; | 1932 | QString partA, partB, result; |
1933 | char endCh = '>'; | 1933 | char endCh = '>'; |
1934 | 1934 | ||
1935 | startPos = rawEmail.find('<'); | 1935 | startPos = rawEmail.find('<'); |
1936 | if (startPos < 0) | 1936 | if (startPos < 0) |
1937 | { | 1937 | { |
1938 | startPos = rawEmail.find('('); | 1938 | startPos = rawEmail.find('('); |
1939 | endCh = ')'; | 1939 | endCh = ')'; |
1940 | } | 1940 | } |
1941 | if (startPos < 0) | 1941 | if (startPos < 0) |
1942 | { | 1942 | { |
1943 | // We couldn't find any separators, so we assume the whole string | 1943 | // We couldn't find any separators, so we assume the whole string |
1944 | // is the email address | 1944 | // is the email address |
1945 | email = rawEmail; | 1945 | email = rawEmail; |
1946 | fullName = ""; | 1946 | fullName = ""; |
1947 | } | 1947 | } |
1948 | else | 1948 | else |
1949 | { | 1949 | { |
1950 | // We have a start position, try to find an end | 1950 | // We have a start position, try to find an end |
1951 | endPos = rawEmail.find(endCh, startPos+1); | 1951 | endPos = rawEmail.find(endCh, startPos+1); |
1952 | 1952 | ||
1953 | if (endPos < 0) | 1953 | if (endPos < 0) |
1954 | { | 1954 | { |
1955 | // We couldn't find the end of the email address. We can only | 1955 | // We couldn't find the end of the email address. We can only |
1956 | // assume the entire string is the email address. | 1956 | // assume the entire string is the email address. |
1957 | email = rawEmail; | 1957 | email = rawEmail; |
1958 | fullName = ""; | 1958 | fullName = ""; |
1959 | } | 1959 | } |
1960 | else | 1960 | else |
1961 | { | 1961 | { |
1962 | // We have a start and end to the email address | 1962 | // We have a start and end to the email address |
1963 | 1963 | ||
1964 | // Grab the name part | 1964 | // Grab the name part |
1965 | fullName = rawEmail.left(startPos).stripWhiteSpace(); | 1965 | fullName = rawEmail.left(startPos).stripWhiteSpace(); |
1966 | 1966 | ||
1967 | // grab the email part | 1967 | // grab the email part |
1968 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); | 1968 | email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); |
1969 | 1969 | ||
1970 | // Check that we do not have any extra characters on the end of the | 1970 | // Check that we do not have any extra characters on the end of the |
1971 | // strings | 1971 | // strings |
1972 | len = fullName.length(); | 1972 | len = fullName.length(); |
1973 | if (fullName[0]=='"' && fullName[len-1]=='"') | 1973 | if (fullName[0]=='"' && fullName[len-1]=='"') |
1974 | fullName = fullName.mid(1, len-2); | 1974 | fullName = fullName.mid(1, len-2); |
1975 | else if (fullName[0]=='<' && fullName[len-1]=='>') | 1975 | else if (fullName[0]=='<' && fullName[len-1]=='>') |
1976 | fullName = fullName.mid(1, len-2); | 1976 | fullName = fullName.mid(1, len-2); |
1977 | else if (fullName[0]=='(' && fullName[len-1]==')') | 1977 | else if (fullName[0]=='(' && fullName[len-1]==')') |
1978 | fullName = fullName.mid(1, len-2); | 1978 | fullName = fullName.mid(1, len-2); |
1979 | } | 1979 | } |
1980 | } | 1980 | } |
1981 | } | 1981 | } |
1982 | 1982 | ||
1983 | void Addressee::setResource( Resource *resource ) | 1983 | void Addressee::setResource( Resource *resource ) |
1984 | { | 1984 | { |
1985 | detach(); | 1985 | detach(); |
1986 | mData->resource = resource; | 1986 | mData->resource = resource; |
1987 | } | 1987 | } |
1988 | 1988 | ||
1989 | Resource *Addressee::resource() const | 1989 | Resource *Addressee::resource() const |
1990 | { | 1990 | { |
1991 | return mData->resource; | 1991 | return mData->resource; |
1992 | } | 1992 | } |
1993 | 1993 | ||
1994 | //US | 1994 | //US |
1995 | QString Addressee::resourceLabel() | 1995 | QString Addressee::resourceLabel() |
1996 | { | 1996 | { |
1997 | return i18n("Resource"); | 1997 | return i18n("Resource"); |
1998 | } | 1998 | } |
1999 | QString Addressee::categoryLabel() | ||
2000 | { | ||
2001 | return i18n("Category"); | ||
2002 | } | ||
1999 | 2003 | ||
2000 | void Addressee::setChanged( bool value ) | 2004 | void Addressee::setChanged( bool value ) |
2001 | { | 2005 | { |
2002 | detach(); | 2006 | detach(); |
2003 | mData->changed = value; | 2007 | mData->changed = value; |
2004 | } | 2008 | } |
2005 | 2009 | ||
2006 | bool Addressee::changed() const | 2010 | bool Addressee::changed() const |
2007 | { | 2011 | { |
2008 | return mData->changed; | 2012 | return mData->changed; |
2009 | } | 2013 | } |
2010 | 2014 | ||
2011 | void Addressee::setTagged( bool value ) | 2015 | void Addressee::setTagged( bool value ) |
2012 | { | 2016 | { |
2013 | detach(); | 2017 | detach(); |
2014 | mData->tagged = value; | 2018 | mData->tagged = value; |
2015 | } | 2019 | } |
2016 | 2020 | ||
2017 | bool Addressee::tagged() const | 2021 | bool Addressee::tagged() const |
2018 | { | 2022 | { |
2019 | return mData->tagged; | 2023 | return mData->tagged; |
2020 | } | 2024 | } |
2021 | 2025 | ||
2022 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) | 2026 | QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) |
2023 | { | 2027 | { |
2024 | if (!a.mData) return s; | 2028 | if (!a.mData) return s; |
2025 | 2029 | ||
2026 | s << a.uid(); | 2030 | s << a.uid(); |
2027 | 2031 | ||
2028 | s << a.mData->name; | 2032 | s << a.mData->name; |
2029 | s << a.mData->formattedName; | 2033 | s << a.mData->formattedName; |
2030 | s << a.mData->familyName; | 2034 | s << a.mData->familyName; |
2031 | s << a.mData->givenName; | 2035 | s << a.mData->givenName; |
2032 | s << a.mData->additionalName; | 2036 | s << a.mData->additionalName; |
2033 | s << a.mData->prefix; | 2037 | s << a.mData->prefix; |
2034 | s << a.mData->suffix; | 2038 | s << a.mData->suffix; |
2035 | s << a.mData->nickName; | 2039 | s << a.mData->nickName; |
2036 | s << a.mData->birthday; | 2040 | s << a.mData->birthday; |
2037 | s << a.mData->mailer; | 2041 | s << a.mData->mailer; |
2038 | s << a.mData->timeZone; | 2042 | s << a.mData->timeZone; |
2039 | s << a.mData->geo; | 2043 | s << a.mData->geo; |
2040 | s << a.mData->title; | 2044 | s << a.mData->title; |
2041 | s << a.mData->role; | 2045 | s << a.mData->role; |
2042 | s << a.mData->organization; | 2046 | s << a.mData->organization; |
2043 | s << a.mData->note; | 2047 | s << a.mData->note; |
2044 | s << a.mData->productId; | 2048 | s << a.mData->productId; |
2045 | s << a.mData->revision; | 2049 | s << a.mData->revision; |
2046 | s << a.mData->sortString; | 2050 | s << a.mData->sortString; |
2047 | s << a.mData->url; | 2051 | s << a.mData->url; |
2048 | s << a.mData->secrecy; | 2052 | s << a.mData->secrecy; |
2049 | s << a.mData->logo; | 2053 | s << a.mData->logo; |
2050 | s << a.mData->photo; | 2054 | s << a.mData->photo; |
2051 | s << a.mData->sound; | 2055 | s << a.mData->sound; |
2052 | s << a.mData->agent; | 2056 | s << a.mData->agent; |
2053 | s << a.mData->phoneNumbers; | 2057 | s << a.mData->phoneNumbers; |
2054 | s << a.mData->addresses; | 2058 | s << a.mData->addresses; |
2055 | s << a.mData->emails; | 2059 | s << a.mData->emails; |
2056 | s << a.mData->categories; | 2060 | s << a.mData->categories; |
2057 | s << a.mData->custom; | 2061 | s << a.mData->custom; |
2058 | s << a.mData->keys; | 2062 | s << a.mData->keys; |
2059 | return s; | 2063 | return s; |
2060 | } | 2064 | } |
2061 | 2065 | ||
2062 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) | 2066 | QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) |
2063 | { | 2067 | { |
2064 | if (!a.mData) return s; | 2068 | if (!a.mData) return s; |
2065 | 2069 | ||
2066 | s >> a.mData->uid; | 2070 | s >> a.mData->uid; |
2067 | 2071 | ||
2068 | s >> a.mData->name; | 2072 | s >> a.mData->name; |
2069 | s >> a.mData->formattedName; | 2073 | s >> a.mData->formattedName; |
2070 | s >> a.mData->familyName; | 2074 | s >> a.mData->familyName; |
2071 | s >> a.mData->givenName; | 2075 | s >> a.mData->givenName; |
2072 | s >> a.mData->additionalName; | 2076 | s >> a.mData->additionalName; |
2073 | s >> a.mData->prefix; | 2077 | s >> a.mData->prefix; |
2074 | s >> a.mData->suffix; | 2078 | s >> a.mData->suffix; |
2075 | s >> a.mData->nickName; | 2079 | s >> a.mData->nickName; |
2076 | s >> a.mData->birthday; | 2080 | s >> a.mData->birthday; |
2077 | s >> a.mData->mailer; | 2081 | s >> a.mData->mailer; |
2078 | s >> a.mData->timeZone; | 2082 | s >> a.mData->timeZone; |
2079 | s >> a.mData->geo; | 2083 | s >> a.mData->geo; |
2080 | s >> a.mData->title; | 2084 | s >> a.mData->title; |
2081 | s >> a.mData->role; | 2085 | s >> a.mData->role; |
2082 | s >> a.mData->organization; | 2086 | s >> a.mData->organization; |
2083 | s >> a.mData->note; | 2087 | s >> a.mData->note; |
2084 | s >> a.mData->productId; | 2088 | s >> a.mData->productId; |
2085 | s >> a.mData->revision; | 2089 | s >> a.mData->revision; |
2086 | s >> a.mData->sortString; | 2090 | s >> a.mData->sortString; |
2087 | s >> a.mData->url; | 2091 | s >> a.mData->url; |
2088 | s >> a.mData->secrecy; | 2092 | s >> a.mData->secrecy; |
2089 | s >> a.mData->logo; | 2093 | s >> a.mData->logo; |
2090 | s >> a.mData->photo; | 2094 | s >> a.mData->photo; |
2091 | s >> a.mData->sound; | 2095 | s >> a.mData->sound; |
2092 | s >> a.mData->agent; | 2096 | s >> a.mData->agent; |
2093 | s >> a.mData->phoneNumbers; | 2097 | s >> a.mData->phoneNumbers; |
2094 | s >> a.mData->addresses; | 2098 | s >> a.mData->addresses; |
2095 | s >> a.mData->emails; | 2099 | s >> a.mData->emails; |
2096 | s >> a.mData->categories; | 2100 | s >> a.mData->categories; |
2097 | s >> a.mData->custom; | 2101 | s >> a.mData->custom; |
2098 | s >> a.mData->keys; | 2102 | s >> a.mData->keys; |
2099 | 2103 | ||
2100 | a.mData->empty = false; | 2104 | a.mData->empty = false; |
2101 | 2105 | ||
2102 | return s; | 2106 | return s; |
2103 | } | 2107 | } |
2104 | bool matchBinaryPattern( int value, int pattern ) | 2108 | bool matchBinaryPattern( int value, int pattern ) |
2105 | { | 2109 | { |
2106 | /** | 2110 | /** |
2107 | We want to match all telephonnumbers/addresses which have the bits in the | 2111 | We want to match all telephonnumbers/addresses which have the bits in the |
2108 | pattern set. More are allowed. | 2112 | pattern set. More are allowed. |
2109 | if pattern == 0 we have a special handling, then we want only those with | 2113 | if pattern == 0 we have a special handling, then we want only those with |
2110 | exactly no bit set. | 2114 | exactly no bit set. |
2111 | */ | 2115 | */ |
2112 | if ( pattern == 0 ) | 2116 | if ( pattern == 0 ) |
2113 | return ( value == 0 ); | 2117 | return ( value == 0 ); |
2114 | else | 2118 | else |
2115 | return ( pattern == ( pattern & value ) ); | 2119 | return ( pattern == ( pattern & value ) ); |
2116 | } | 2120 | } |
2117 | 2121 | ||
2118 | bool matchBinaryPatternP( int value, int pattern ) | 2122 | bool matchBinaryPatternP( int value, int pattern ) |
2119 | { | 2123 | { |
2120 | 2124 | ||
2121 | if ( pattern == 0 ) | 2125 | if ( pattern == 0 ) |
2122 | return ( value == 0 ); | 2126 | return ( value == 0 ); |
2123 | else | 2127 | else |
2124 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); | 2128 | return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); |
2125 | } | 2129 | } |
2126 | bool matchBinaryPatternA( int value, int pattern ) | 2130 | bool matchBinaryPatternA( int value, int pattern ) |
2127 | { | 2131 | { |
2128 | 2132 | ||
2129 | if ( pattern == 0 ) | 2133 | if ( pattern == 0 ) |
2130 | return ( value == 0 ); | 2134 | return ( value == 0 ); |
2131 | else | 2135 | else |
2132 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); | 2136 | return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); |
2133 | } | 2137 | } |