Get the username from the system
| 776 | |
| 777 | // Get the username from the system |
| 778 | QString Global::getUsername() { |
| 779 | |
| 780 | if (!autosetUsername()) |
| 781 | return ""; |
| 782 | |
| 783 | // First, see if the Evernote user record is available |
| 784 | UserTable userTable(db); |
| 785 | User user; |
| 786 | userTable.getUser(user); |
| 787 | if (user.name.isSet()) |
| 788 | return user.name; |
| 789 | // Windows Check |
| 790 | #ifndef _WIN32 |
| 791 | register struct passwd *pw; |
| 792 | register uid_t uid; |
| 793 | QString username=""; |
| 794 | |
| 795 | uid = geteuid(); |
| 796 | pw = getpwuid(uid); |
| 797 | if (pw) { |
| 798 | username = pw->pw_gecos; |
| 799 | username.remove(QChar(',')); |
| 800 | if (username != "") |
| 801 | return username.trimmed(); |
| 802 | username = pw->pw_name; |
| 803 | return username.trimmed(); |
| 804 | } |
| 805 | #else |
| 806 | return qgetenv("USERNAME"); |
| 807 | #endif // End Windows Check |
| 808 | |
| 809 | return ""; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | // Determine if we should automatically set the username on new notes |
no test coverage detected